在Windows 7下运行py2exe,无法在Windows XP下执行文件

0 投票
3 回答
2357 浏览
提问于 2025-04-17 00:31

我用py2exe把我的Python+Gtk应用程序做成了一个exe文件。在Windows 7上可以正常运行,但在Windows XP上却无法启动,出现了以下错误:

Traceback (most recent call last):
  File "debug4iConnect.py", line 1, in <module>
  File "startApp.pyc", line 1, in <module>
  File "gtk\__init__.pyc", line 40, in <module>
  File "gtk\_gtk.pyc", line 12, in <module>
  File "gtk\_gtk.pyc", line 10, in __load
ImportError: DLL load failed: Impossibile trovare la procedura specificata.

我尝试用dependency-walker查找缺失的dll文件,得到了这些信息:

LoadLibraryA("c:\......\zlib.pyd") returned NULL. Error: Impossibile trovare il modulo specificato (126).

LoadLibraryExA("c:\.....\gtk._gtk.pyd", 0x00000000, LOAD_WITH_ALTERED_SEARCH_PATH) returned NULL. Error: Impossibile trovare la procedura specificata (127).

"Impossibile trovare la procedura specificata" means: Impossible to find specified procedure. 
"Impossibile trovare il modulo specificato" means: Impossible to find the specified module.

这个帖子似乎有类似的问题,但解决方案对我没用: Py2exe - win32api.pyc ImportError DLL load failed

有没有人知道我该怎么做?

更新: 我再次使用dependencywalker,发现了一些缺失的dll文件:

API-MS-WIN-SECURITY-BASE-L1-1-0.DLL
API-MS-WIN-SECURITY-LSALOOKUP-L1-1-0.DLL
API-MS-WIN-SERVICE-MANAGEMENT-L1-1-0.DLL
API-MS-WIN-SERVICE-MANAGEMENT-L2-1-0.DLL
API-MS-WIN-SERVICE-WINSVC-L1-1-0.DLL
CRYPTBASE.DLL
MSJAVA.DLL,

我把它们加上了,现在出现了这个错误:

GetProcAddress(0x00000000, "CtfImmCoUninitialize") called from "c:\windows\system32
\MSCTF.DLL" at address 0x746B279F and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "CtfImmLastEnabledWndDestroy") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B27DC and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "CtfImmSetCiceroStartInThread") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B281F and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "CtfImmIsCiceroStartedInThread") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B2864 and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "CtfImmIsCiceroEnabled") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B28A9 and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "CtfImmIsTextFrameServiceDisabled") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B28E5 and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "CtfImmEnterCoInitCountSkipMode") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B292C and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "CtfImmLeaveCoInitCountSkipMode") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B2972 and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "ImmGetDefaultIMEWnd") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B29B6 and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "ImmReleaseContext") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B29EF and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "ImmNotifyIME") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B2A29 and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "ImmSetConversionStatus") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B2A5C and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "ImmGetConversionStatus") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B2A9A and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "ImmGetProperty") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B2AD6 and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "ImmGetOpenStatus") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B2B0A and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "ImmGetContext") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B2B40 and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "ImmSetOpenStatus") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B2B75 and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "ImmInstallIMEA") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B2BAC and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "ImmGetDescriptionA") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B2BE2 and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "ImmGetDescriptionW") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B2C1A and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "ImmGetIMEFileNameA") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B2C52 and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "ImmGetIMEFileNameW") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B2C8A and returned NULL. Error: Impossibile trovare la procedura specificata (127).
GetProcAddress(0x00000000, "ImmSetHotKey") called from "c:\windows\system32\MSCTF.DLL" at address 0x746B3168 and returned NULL. Error: Impossibile trovare la procedura specificata (127).

当我运行这个应用程序时,出现了错误:

Fatal Python error: Interpreter not initialized (version mismatch?)

如果我把zlib.pyd删掉,就会出现上面的ImportError。我发现我的zlib.pyd是从python2.4来的,而python2.7没有单独的zlib.pyd,它应该包含在python27.dll里。这样说对吗?

3 个回答

0

我也遇到过这个问题。对我来说,解决办法是把 MSWSOCK.dllPOWRPROF.dll 这两个库排除在外:

setup(
    # other options ommited...
    options={
        "py2exe":{
            "dll_excludes": ["POWRPROF.dll", "MSWSOCK.dll"]
        }
    },
)

这样也就把所有的 MS_API_*.dll 文件都去掉了。

0

你可以使用依赖关系查看器来找出缺少的dll文件。

可能你需要在XP电脑上安装Visual Studio的运行库。

1

解决了:我设置了 "bundle_files": 3"skip_archive": True,现在可以正常工作了。

撰写回答