Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
540 views
in Technique[技术] by (71.8m points)

python - Py2exe - win32api.pyc ImportError DLL load failed

I am trying to use py2exe to distribute a python application I have written. Everything seems to go OK, but when I run it on another machine it fails with the following error:

Traceback (most recent call last):
  File "application.py", line 12, in <module>
  File "win32api.pyc", line 12, in <module>
  File "win32api.pyc", line 10, in __load
ImportError: DLL load failed: The specified procedure could not be found.

I have googled for this and not found very much, but have tried the following suggestions to no avail:

Imported pywintypes and pythoncom before win32api (in the setup.py for py2exe and in the main application) Added some code to the setup.py -

# ModuleFinder can't handle runtime changes to __path__, but win32com uses them
import pywintypes
import pythoncom
import win32api
try:
# if this doesn't work, try import modulefinder
    import py2exe.mf as modulefinder
    import win32com
    for p in win32com.__path__[1:]:
        modulefinder.AddPackagePath("win32com", p)
    for extra in ["win32com.shell"]: #,"win32com.mapi"
        __import__(extra)
        m = sys.modules[extra]
        for p in m.__path__[1:]:
            modulefinder.AddPackagePath(extra, p)
except ImportError:
    # no build path setup, no worries.
    pass

I'm quite new to all this, so any help would be greatly appreciated

Thanks

Jon

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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" ]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...