没有使用C ++中嵌入的python命名为__future__的模块

时间:2018-12-27 02:36:58

标签: python c++ anaconda

我正在使用Visual Studio从CPP文件调用python函数。我的默认python环境是Anaconda 5.3.0。当我在Anaconda提示符下运行.py文件本身时,它可以工作。但是,当我尝试通过将其嵌入CPP文件中来调用该函数时,出现以下错误。

ModuleNotFoundError: No module named '__future__'

将来的文件确实在我的anaconda环境中,并且可以在anaconda提示符下工作。但是由于某种原因,即使将默认的python环境设置为Anaconda,将其嵌入C ++并通过Visual Studio运行时也不起作用。

这是我的CPP文件的以下代码。

// Initialize the Python interpreter.
Py_Initialize();

PySys_SetPath(L"filepath");

// Convert the file name to a Python string.
PyObject *pName = PyUnicode_FromString("filename");
// Import the module
PyObject *pModule = PyImport_Import(pName);
if (pModule) {
    //do stuff
}
else {
    PyErr_Print();
    return 0;
}

谢谢!

0 个答案:

没有答案