I can load Python modules (.py, .pyc, .pyd) from a zip file by calling "import some_module" from a Python interpreter only after sys.path has been extended to include the zip file and only after I have run
import zipextimporter
zipextimporter.install()
The latter is required for .pyd modules.
I can also load Python .py and .pyc modules from Python embedded in C++. However, in order to also load .pyd modules from embedded Python I added
PyRun_SimpleString("import zipextimporter");
The C++ exe runs beyond this line without error. But the next command
PyRun_SimpleString("zipextimporter.install()");
gives me this error:
Why does zipextimporter.install() crash when Python is embedded?
How can I solve this?
Does it perhaps have to do with the way the C++ code is compiled? I use g++:
g++ embed-simple.cpp -IE:\Python27\include -LE:\Python27\libs -lpython27 -o embed-simple
I saw a link How to link against msvcr90.dll with mingw gcc?
Could that provide a solution? If yes, how should I adjust it, gcc-->g++, since I am running C++ code, not C.
I am running Python 2.7.2 on WinXP.
I don't get the runtime error after a clean install of Python 2.7.2, just this:
Import Error: No module named....
Would it matter the way the embedding C++ script is compiled? I used g++. I also compiled with the Intel compiler, but that gave the same runtime error. Perhaps I should try MS Visual C++.
Or use ctypes to import the pyd?