Home > Back-end >  Vs2015 c call python scripts PyImport_ImportModule always returns null
Vs2015 c call python scripts PyImport_ImportModule always returns null

Time:09-22

I just use the python scripts to other third-party libraries numpy library, such as PyImport_ImportModule will fail, if we do not import these libraries can success
Reference other people's tutorial or useless
https://blog.csdn.net/m0_38125278/article/details/87191971{
Py_SetPythonHome (L "D:/Python/Python36.8");
Py_Initialize ();//load the Python interpreter
if (! Py_IsInitialized ()) {
//printf (" Python envirment initialized successfully!" );
return 0;
}
PyRun_SimpleString (" import sys ");
PyRun_SimpleString (" sys. Path. Append ('/') ");
//PyRun_SimpleString (" sys. Path. Append (' D:/Python/Python36.8/Lib) ");

The PyObject * pModule=NULL;
The PyObject * pFunc=NULL;
The PyObject * pArgs=NULL;
The PyObject * pResult=NULL;
PModule=PyImport_ImportModule (" test ");//Python py filename


Py_Finalize ();//uninstall Python interpreter
}
  • Related