windows 尝试运行 py2exe 应用程序时出现 MemoryLoadError
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2104611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MemoryLoadError when trying to run py2exe application
提问by Benjamin Pollack
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:
我正在尝试在 Windows 上使用 py2exe 0.6.9 和 Python 2.6.4 捆绑 Python 应用程序。虽然可执行文件在我用来构建它的系统上运行得很好,但当我尝试在另一个系统上运行它时它会失败:
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?
我有一种强烈的预感,我缺少一个库,但我不确定是哪个 - 特别是因为依赖项检查器没有将目标系统上的任何内容标记为丢失。我应该如何进行?
回答by istonelee
same question as https://stackoverflow.com/questions/1979486/py2exe-win32api-pyc-importerror-dll-load-failed.
与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.
看看setup.py,只排除系统中包含的这些dll。
'dll_excludes': [ "mswsock.dll", "powrprof.dll" ]
it will help you!
它会帮助你!
回答by Paul
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.
您可以手动执行 dll 和依赖项检查。当您生成 exe 时,我相信您已经注意到它会打印出所需/使用的 dll。检查系统,其中 exe 无法运行,dll 是否存在以及它们是否是相同的版本。
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.
另一件事。您是将整个 dist 文件夹复制到系统还是只复制 exe,因为您需要整个 dist 文件夹而不仅仅是 exe。
回答by PPTim
Are you doing the py2exe conversion on a 64bit/vista?
您是否在 64 位/vista 上进行 py2exe 转换?
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).
我一直在 vista64 位上编写代码,而我创建的 .exe 文件通常无法在 32 位 XP 上运行(这是我手头的两台机器)。
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.
.exe 有用地抛出了一个带有回溯的文本文件,看起来 64 位 Windows 使用 win32api.dll。我假设这是 64 位 Windows 用来复制 32 位操作系统行为的 .dll,所以我只需采用相同的脚本并在 32 位 XP 上进行转换。希望有帮助。
回答by IslamTaha
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:
只为将来会来这里的任何人。如果您正在使用任何类型的 win32 库并且您遇到此类错误,您可以执行以下步骤:
- 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
- 问题是win32函数的dll文件和py2exe自动生成的dll文件有冲突。所以要解决这个冲突,你必须知道你的函数需要 dll 文件,然后从设置选项中排除这些文件
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.
我使用了 CryptUnprotectData 函数,所以我搜索了 CryptUnprotectData 所需的 dll,我发现以下信息在此处输入链接描述,如您所见,需要
“Crypt32.dll”。
so I edit my setup.py to be look like that
所以我编辑我的 setup.py 看起来像那样
includes = ["win32crypt"]
dll_excludes=["Crypt32.dll"]
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': True,'dll_excludes': dll_excludes,'includes': includes}})
and it worked perfectly.
它工作得很好。