Question

I am attempting to bundle up a Python application using py2exe 0.6.9 and Python 2.6.4 on Windows. While the executable runs just fine on the system I used to build it, it fails when I attempt to run it on another system:

C:\Documents and Settings\Administrator\Desktop\dist>.\backend.exe install
Traceback (most recent call last):
  File "boot_service.py", line 6, in <module>
  File "zipextimporter.pyo", line 82, in load_module
  File "win32serviceutil.pyo", line 9, in <module>
  File "zipextimporter.pyo", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading win32api.pyd

I have a strong hunch that I'm missing a library, but I'm unsure which—especially since the dependency checker isn't flagging anything as missing on the target system. How should I proceed?

Was it helpful?

Solution

same question as https://stackoverflow.com/questions/1979486/py2exe-win32api-pyc-importerror-dll-load-failed.

look at setup.py, just excludes these dlls which are included in the system.

 'dll_excludes': [ "mswsock.dll", "powrprof.dll" ]

it will help you!

OTHER TIPS

You can do the dll and dependency check manually. When you generate the exe i am sure you have noticed that it prints out the dll's that are required/used. Check on the system, where the exe is not working, if the dll's exist and if they are the same version.

One other thing. Are you copying the whole dist folder to the system or just the exe, because you need the whole dist folder and not just the exe.

Are you doing the py2exe conversion on a 64bit/vista?

I've been writing my code on a vista64bit, and the .exe files I create usually do not work on 32bit XP (those are the two machines i have on hand).

The .exe helpfully throws out a text file with the traceback, and it appears that the 64bit windows uses the win32api.dll. I assume this is a .dll used by 64bit windows to replicate 32bit OS behaviour, so I simply take the same script and do the conversion on the 32bit XP. Hope that helps.

Just for anyone who will come to here in the future. If you are using any kind of win32 library and u stuck with this type of errors you can do the following steps:

  • The problem issue is that there is a conflict between win32 functions dll files and the py2exe automatically dll files. So to solve this conflict you have to know your functions required dll files, then exclude these files from the setup options

Example:

According to the following code:

import win32crypt
win32crypt.CryptUnprotectData(...)

I used the CryptUnprotectData function so I searched for the CryptUnprotectData required dll and I found the following info enter link description here , As u can see,
"Crypt32.dll" is required.

so I edit my setup.py to be look like that

includes = ["win32crypt"]
dll_excludes=["Crypt32.dll"]


setup(
    options = {'py2exe': {'bundle_files': 1, 'compressed': True,'dll_excludes': dll_excludes,'includes': includes}})

and it worked perfectly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top