我正在构建一个C++应用程序,将调用Python + NumPy,并希望延迟加载Python DLL。我在Windows上使用64位Python 3.6和Visual Studio 2015。只要我不使用NumPy,DELAYLOAD就能正常工作。一旦我调用
有没有办法在使用numpy时实现延迟加载?
或者说,有没有办法在不调用import_array()的情况下创建并填充数据到numpy.recarray中?
编辑:我决定摆脱import_array()。 这是我用来初始化Python的一些代码:
import_array()
,我就不能再使用DELAYLOAD选项进行构建。链接器错误为:
LNK1194 由于导入数据符号'__imp_PyExc_ImportError',无法延迟加载'python36.dll';请在没有/DELAYLOAD:python36.dll的情况下进行链接。
这是我的代码:
// Initialize python
Py_Initialize();
// If I remove this line, I am able to build with DELAYLOAD
import_array();
有没有办法在使用numpy时实现延迟加载?
或者说,有没有办法在不调用import_array()的情况下创建并填充数据到numpy.recarray中?
编辑:我决定摆脱import_array()。 这是我用来初始化Python的一些代码:
if (!Py_IsInitialized())
{
// Initialize Python
Py_Initialize();
// Initialize threads
PyEval_InitThreads();
// Needed for datetime
PyDateTime_IMPORT;
// Needed to avoid use of Py_None, Py_True, and Py_False;
// which cause inability to use DELAYLOAD
HMODULE pythonDll = GetModuleHandle(L"python36.dll");
if (pythonDll == nullptr)
{
throw gcnew NotSupportedException(L"GS_ERR_CannotInitialize");
}
PythonHelper::_pyNone = (PyObject*)GetProcAddress(pythonDll, "_Py_NoneStruct");
PythonHelper::_pyTrue = (PyObject*)GetProcAddress(pythonDll, "_Py_TrueStruct");
PythonHelper::_pyFalse = (PyObject*)GetProcAddress(pythonDll, "_Py_FalseStruct");
}
Python.h
? - sancho.s ReinstateMonicaCellio#pragma unmanaged #include
#include "Python.h"
#include "datetime.h"
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include "numpy/arrayobject.h"
#pragma managed
#include
- Andrey Belykh