开发者

py2exe throws ImportError: DLL load failed: The specified module could not be found

开发者 https://www.devze.com 2023-02-21 17:07 出处:网络
I cannot seem to get py2exe to work properly.I have run \"python setup.py py2exe\" in cmd, as well as \"python setup.py install\"... and When I try to run my executable setup, I get this same error ov

I cannot seem to get py2exe to work properly. I have run "python setup.py py2exe" in cmd, as well as "python setup.py install"... and When I try to run my executable setup, I get this same error over and over:

py2exe throws ImportError: DLL load failed: The specified module could not be found

After a week I'm starting to get quite frustrated and I'm hoping to be able to开发者_高级运维 resolve the issue today.

I'm using Python 2.7 and py2exe v0.6.9. 64-bit Windows7


FINALLY, I can die a happy man. After agonizing over this problem for over a week, I figured out that the issue is that I had to download the 64bit version of py2exe from SourceForge. The "Get Latest Version" link that they have at the top is for Python 2.5, which is very misleading because I would have assumed it would at least use the latest version of PYTHON that it supports, which I believe is the version I have, Python 2.7.1.

I had to go into the "Browse All Files" section and manually navigate to v0.6.9 and then pick the appropriate version.

I am now able to create an executable from running "C:\Python27\setup.py py2exe".

thanks all for your help/replies.


The most important lines in that error are the last two -

import py2exe_util

ImportError: DLL load failed: The specified module could not be found.

That means py2exe was not installed completely in the first place. Try re-installing it.


You need a version of py2exe that matches the architecture of your python install. If you have a 32bit python install you need a win32 py2exe installer. If you have a x64 python install you need a win64 py2exe installer.

In my case I am on a 64bit machine with a 32bit python install. The Source Forge 'latest' link gave the win64 version of py2exe (because it detected my machine type). But it didn't work, I kept getting the following error:

ImportError: DLL load failed with error code 193

I needed to go back to Source Forge and 'Browse all files' to find the win32 version.


I'm not sure my problem is the same as OPs, but since I found this thread while searching for a solution to my problem, I'll add what I found.

My issue was building 32 bit program on a 64 bit machine. The exe worked fine on other 64 bit machines, but raised the DLL load failed: The specified module could not be found error on other 32 bit machines.

What I ended up figuring out was that py2exe was including windows DLLs that it shouldn't have been in the package. When these DLLs were removed, the error went away.

py2exe has an option to explicitly exclude dlls. Here's a snippet of what worked for me:

setup(
    ...
    options={
        'bdist_esky': {
            'freezer_module': 'py2exe',
            'freezer_options': {
                'dll_excludes': [
                    'CRYPT32.dll',
                    'IPHLPAPI.DLL',
                    'MPR.dll',
                    'MSWSOCK.dll',
                    'PSAPI.DLL',
                    'WTSAPI32.dll',
                ],
            },
            ...
)
0

精彩评论

暂无评论...
验证码 换一张
取 消