Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105285 > unrolled thread
| Started by | Sgoodman <siminfrance@gmail.com> |
|---|---|
| First post | 2016-03-19 11:12 -0700 |
| Last post | 2016-03-19 11:12 -0700 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
Bug in embeddable code or in my code? Sgoodman <siminfrance@gmail.com> - 2016-03-19 11:12 -0700
| From | Sgoodman <siminfrance@gmail.com> |
|---|---|
| Date | 2016-03-19 11:12 -0700 |
| Subject | Bug in embeddable code or in my code? |
| Message-ID | <5126641d-d2e2-42e9-81d7-b599e805dee2@googlegroups.com> |
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.
Back to top | Article view | comp.lang.python
csiph-web