Bug in embeddable code or in my code?

Sgoodman siminfrance at gmail.com
Sat Mar 19 14:12:02 EDT 2016


Hi, 
When I run the code below, I manage to execute certain python code but not some simple imports.
For example, the code below... (I removed some error checking/reference checks for brevity)
 // ...
 Py_SetProgramName(L"AAAAA");
 Py_SetPath(L"path\\to\\python35.zip"); // embeddable from the python site.
 Py_Initialize();
 PyThreadState *mainstate = PyThreadState_Get();
 PyInterpreterState* mainInterpreterState = mainstate->interp;
 
 PyObject *main_module = PyImport_AddModule("__main__");
 PyObject *main_dict = PyModule_GetDict(main_module);
 PyObject *local_dic = PyDict_New();
 
 const char* s = "import ctypes\n";
 PyObject * PyRes = PyRun_String(s, Py_file_input, main_dict, local_dic);
 PyObject* ex = PyErr_Occurred();
 if (NULL != ex)
 {
 // didn't work, import error.
 }
 // cleanup...
 // ...
I can do some imports, ("import sys" for example), but most of the others do not work, "import ctypes" for example.
Any suggestions as to what I might be missing?
S.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /