Download pyd files from zip from embedded python

I can load Python modules (.py, .pyc, .pyd) from a zip file by calling "import some_module" from the Python interpreter only after the sys.path has been expanded to include the zip file and only after I 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, to also load .pyd modules from embedded Python, I added

 PyRun_SimpleString("import zipextimporter"); 

C ++ exe goes beyond this line without errors. But the next team

 PyRun_SimpleString("zipextimporter.install()"); 

gives me this error:

enter image description here

Why does zipextimporter.install () fail when inserting Python?

How can i solve this?

Perhaps this is due to how C ++ code compiles? I am using g ++:

g++ embed-simple.cpp -IE:\Python27\include -LE:\Python27\libs -lpython27 -o embed-simple

I saw the link How to link to msvcr90.dll with mingw gcc?

Could this provide a solution? If so, how do I configure it, gcc β†’ g ++, since I am running the code in C ++, not C.

I am running Python 2.7.2 on WinXP.

I am not getting a runtime error after a clean install of Python 2.7.2, only this:

Import error: no module named ....

Will it matter how the C ++ script attachment is compiled? I used g ++. I also compiled using the Intel compiler, but it gave the same runtime error. Maybe I should try MS Visual C ++.

Or use ctypes to import pyd?

+6
source share
4 answers

memimporter and zipextimporter can actually download .pyd files from memory / zip archives without unpacking them into files.

Runtimerror R6034 is caused by the VC9 runtime library being loaded through the manifest. Running code in Python 2.5 that uses a different C runtime is likely to be successful. I think you should embed a manifest that references the VC9 runtime library in your exe; perhaps py2exe wiki can give some recommendations.

+5
source

PYD files are native DLL files with a renamed extension. Downloading them depends on the capabilities of the operating system and the limitations of the operating system.

Windows XP or any OS, as far as I know, cannot load DLL files from ZIP files, therefore you cannot load PYD files from ZIP files.

+4
source

What version of python was memimporter.pyd (which is inside zipextimporter) compiled? If the python interpreter and pyd do not match, you will get terrible crashes.

I'm not sure where the mem importer code is, but assuming I think the idea is to insert an import hook that detects zip-based pyd imports and fetches pyd at a temporary location and calls the Standard Python interpreter import.

+2
source

this seems to be the same problems i was trying to compile the application with py2exe with. take a look here: http://www.py2exe.org/index.cgi/Tutorial , see section 5.2. The same thing happens ... The first time you try to use memimporter, it crashes with a similar error message. Basically, for python 2.6+ you need to have the exact version of the runtime library in the path and the manifest that points to it. Since you are using built-in python, I don’t know how it all works, but maybe this will help you closer.

I would start by placing the β€œcorrect” version of the runtime dll somewhere, and in your python code, before importing zipextimporter, add the path to the correct runtime to sys.path and see if that fixes this. not sure how you get there manifest for inline python. it can be included in the manifest of the parent application.

edit: BTW, I forgot, we found another way around this problem. I forget the exact details, but it happens that your application loads the default runtime version and then python requests its version and finds it in c: \ python {26,27} and it does not match. The easiest way to solve this problem is to remove c: \ python \ msvcr90.dll. Then python will not hit the local (old) version of the dll, which may not work with your application manifest, and they will have to exit the current Windows directory, which will correspond.

+2
source

Source: https://habr.com/ru/post/904299/


All Articles