load pyd files from a zip from embedded python
Question: 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:

![enter image description here](http://i.stack.imgur.com/3iYeR.png)

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?](http://stackoverflow.com/questions/3402252/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?


Answer: memimporter and zipextimporter are indeed able to load .pyd files from
memory/zip-archives without unpacking them to files.

The runtimerror R6034 is caused by the fact that the VC9 runtime library must
be loaded via a manifest. Running your code in Python 2.5, whic uses a
different C runtime, would most probably succeed. I guess you must embed a
manifest referencing the VC9 runtime library in your exe; maybe the py2exe
wiki can provide some guidance.

