Py2exe - win32api.pyc ImportError DLL load failed

荒凉一梦 提交于 2019-11-27 19:55:44

I've seen this problem when the package was built on Vista but executed on XP. The problem turned out to be that py2exe mistakenly added powrprof.dll and mswsock.dll to the package. Windows XP contains its own copies of these files though, and can't load the Vista ones which got installed with your app.

Removing them from the package did the trick, you can do this easy by adding this to the options dict in setup.py

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

@Wim, I found the bit about "adding this to the options dict in setup.py" a bit confusing. If like me you did not have an options arg in your existing call to setup this might make things clearer:

setup(name='myprog',     
      ...
      options={"py2exe":{"dll_excludes":[ "mswsock.dll", "powrprof.dll" ]}},
      ...
      )

Try adding win32api to your packages, in the options dictionary.

Here's an example:

excludes = ["pywin", "pywin.debugger"] # there will be more in real life...
options = dict(optimize=2,
           dist_dir="build",
           excludes=excludes,
           packages=["win32api"]) 
setup(
    name="MyCoolApp",
    options=dict(py2exe=options),
    # etc ...

Just as an added comment. When rebuilding your program with Py2exe be sure to delete the old "dist" directory. I was sitting for over 3 hours not understanding why my app was working on my dev envirnoment and not in production. deleted dist and rebuild with py2exe and it worked.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!