Py2Exe:DLL 加载失败

发布于 2024-09-25 03:55:37 字数 1250 浏览 8 评论 0原文

当尝试使用 py2exe 将我制作的简单 Python 游戏转换为 exe 格式时,它给了我以下错误:

Traceback (most recent call last):
  File "C:\Users\Tali\Desktop\2exe.py", line 4, in <module>
    setup(console=['test.py'])
  File "C:\Python\lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "C:\Python\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\Python\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Python\lib\site-packages\py2exe\build_exe.py", line 243, in run
    self._run()
  File "C:\Python\lib\site-packages\py2exe\build_exe.py", line 305, in _run
    dlls = self.find_dlls(extensions)
  File "C:\Python\lib\site-packages\py2exe\build_exe.py", line 389, in find_dlls

    self.dll_excludes)
  File "C:\Python\lib\site-packages\py2exe\build_exe.py", line 1021, in find_dep
endend_dlls
    import py2exe_util
ImportError: DLL load failed: %1 is not a valid Win32 application.

我在网上搜索了大约一个小时,尝试更改程序中的内容。什么都不起作用。 虽然我的程序使用“随机”库,但我还没有看到它导致此类问题的案例。

安装脚本:

from distutils.core import setup
import py2exe

setup(console=['test.py'])

是的,两个脚本都位于同一文件夹(桌面)中。如果重要的话,我正在 Windows Vista 上运行 Python 2.7

提前非常感谢大家。

When trying to use py2exe to convert a simple Python game I made into exe format, it gave me the following error:

Traceback (most recent call last):
  File "C:\Users\Tali\Desktop\2exe.py", line 4, in <module>
    setup(console=['test.py'])
  File "C:\Python\lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "C:\Python\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\Python\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Python\lib\site-packages\py2exe\build_exe.py", line 243, in run
    self._run()
  File "C:\Python\lib\site-packages\py2exe\build_exe.py", line 305, in _run
    dlls = self.find_dlls(extensions)
  File "C:\Python\lib\site-packages\py2exe\build_exe.py", line 389, in find_dlls

    self.dll_excludes)
  File "C:\Python\lib\site-packages\py2exe\build_exe.py", line 1021, in find_dep
endend_dlls
    import py2exe_util
ImportError: DLL load failed: %1 is not a valid Win32 application.

I searched the web for about an hour, tried changing things in my program. Nothing works.
Although my program uses the "random" library, I haven't seen a case in which it caused this kind of problem.

The install script:

from distutils.core import setup
import py2exe

setup(console=['test.py'])

Yes, both the scripts are in the same folder (Desktop). If it matters, I'm running on Windows Vista with Python 2.7

Thank you all very much in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

伏妖词 2024-10-02 03:55:38

我遇到了同样的问题,我在 Windows 7(64 位)上使用 Python 2.7(32 位)和 py2exe-0.6.9.win64-py2.7.amd64.exe,所以问题我使用的是 32 位 Python 和 64 位 py2exe。如果您不知道您使用的Python包是32位还是64位,请从C:\Python27\Lib\idlelib\运行idle.bat。

python窗口提示符中的第一行将显示 python 包的详细信息。

我通过运行“pip uninstall py2exe”卸载了py2exe-0.6.9.win64-py2.7.exe并安装了py2exe-0.6.9.win64- py2.7.amd64.exe 对我有用。

I was facing the same problem, I was using Python 2.7 (32 bits) on Windows 7 (64 bit) with py2exe-0.6.9.win64-py2.7.amd64.exe, so the problem was I was using 32 bit Python and 64 bit py2exe. If you don't know whether Python package you are using is 32 bit or 64 bit, then run idle.bat from C:\Python27\Lib\idlelib\.

The first line in python window prompt will show you the python package details.

I uninstalled the py2exe-0.6.9.win64-py2.7.exe by running "pip uninstall py2exe" and installed py2exe-0.6.9.win64-py2.7.amd64.exe which worked for me.

櫻之舞 2024-10-02 03:55:38

py2exe 看起来很过时。最新版本已经有四年了(从 2014 年开始,今天是 2018 年)

主页“新闻”部分的最新条目是从 2008 年开始(已经有十年了)。

我想如果今天 py2exe 出现错误,最好使用不同的工具。

py2exe looks very dated. The last release is four years old (from 2014, today is 2018)

The latest entry on the homepage part "news" is from 2008 (ten years old).

I guess it is better to use a different tool if you have errors with py2exe today.

坐在坟头思考人生 2024-10-02 03:55:37

我有完全相同的问题。

由于我有windows 7 64位,所以我下载了py2exe-0.6.9.win64-py2.6.amd64.exe,我认为这是py2exe的64位版本。但它不起作用,我也遇到了同样的错误。

我改成py2exe-0.6.9.win32-py2.6.exe,效果很好。

我猜你必须将 32 位或 64 位与 python 安装相匹配,而不是 Windows 本身。

顺便说一句,如果您在 python 安装过程中指示 Windows 使用 python 打开 *.py,那么“setup.py py2exe”或“python setup.py py2exe”实际上并不重要。

I had exact the same problem.

Since I have windows 7 64bit, I downloaded py2exe-0.6.9.win64-py2.6.amd64.exe, which I suppose to be the 64bit version of py2exe. but it did not work, and I had the same error.

I changed to py2exe-0.6.9.win32-py2.6.exe, and it worked fine.

I guess you have to match the 32bit or 64bit with the python installation instead of the windows itself.

by the way, "setup.py py2exe" or "python setup.py py2exe" really does not matter, if you instructed windows to open *.py with python during the python installation.

小…楫夜泊 2024-10-02 03:55:37

我遇到了同样的问题,我搜索了一下,来到了这里。我尝试了小宇提示的方法,但没有成功。所以我从 http://www.py2exe.org/index.cgi/Tutorial# 找到了这个步骤52
5.2.1.捆绑 C 运行时 DLL

如果您确实有权重新分发 MSVCR90.dll,则您的 Visual Studio 安装中应该有一个它的副本,位于 VC\redist\x86\Microsoft.VC90.CRT 下。从 Visual Studio 2008 开始,您不能只复制此 DLL 文件 - 您还需要在那里找到的清单文件。 redist.txt 文件规定您必须分发所有三个 dll 和未修改的清单文件,并且仅分发其中一个 dll 而不分发其他 dll 是违反许可协议的行为(尽管 py2exe 仅需要 MSVCR90.dll)。来自 redist.txt 文件的内容如下:------------------------

所以,尝试一下。

I met the same problem and I searched and I came here . I tried the way prompt by xiao-yu but I didn't work. So I found this from http://www.py2exe.org/index.cgi/Tutorial#Step52
5.2.1. Bundling the C runtime DLL

If you do have the rights to redistribute MSVCR90.dll, there should be a copy of it in your Visual Studio install, under VC\redist\x86\Microsoft.VC90.CRT. Since Visual Studio 2008, you can't just copy this DLL file - you also need the manifest file that you'll find there. The redist.txt file states that you must distribute all three dlls and the unmodified manifest file and it is a violation of the license agreement to distribute only one of the dlls without the others (though py2exe only needs MSVCR90.dll.) The pertinent passage from the redist.txt file is as follows:-----------------------

so ,try it.

§普罗旺斯的薰衣草 2024-10-02 03:55:37

似乎可以通过下载适合您的平台和版本的正确 py2exe 安装程序来解决该问题。

我这里也有同样的问题。我在 Windows 7 64 位上运行并安装了 Python 2.7。我的问题与我安装了 py2exe-0.6.9.win32-py2.7.exe 并且安装程序无法找到 python 相关,即使它找到了安装文件夹。在此阶段运行 python setup.py py2exe 给出了与您所看到的完全相同的错误。

然后我从 此页面并安装它。安装顺利进行,python setup.py py2exe 提供了大量控制台输出,创建了 build 和 dist 文件夹以及预期的可执行文件。

It seems the problem can be solved by downloading the correct py2exe installer for your platform and version.

I had the same problem here too. I was running on Windows 7 64 bit and had installed Python 2.7. My problem had to do with the fact that I installed py2exe-0.6.9.win32-py2.7.exe and the installer was not able to find python, even though it found the installation folder. Running python setup.py py2exe at this stage gave me the exact same errors you're seeing.

I then downloaded py2exe-0.6.9.win64-py2.7.amd64.exe from this page and installed it. The installation went off without a hitch and python setup.py py2exe game me lots of console output, created the build and dist folders and the expected executable.

棒棒糖 2024-10-02 03:55:37

我通过下载“Microsoft Visual C++ Compiler for Python 2.7”解决了这个问题
http://www.microsoft.com/en-pk/download /details.aspx?id=44266

I solved this problem by downloading "Microsoft Visual C++ Compiler for Python 2.7"
http://www.microsoft.com/en-pk/download/details.aspx?id=44266

没有伤那来痛 2024-10-02 03:55:37

你可以处理 py2exe 和头痛,我尝试这样做,即使我做对了,它也会出错,尽管我确实找到了优秀的 python 程序 gui2exe,这使得制作 exe (或任何其他支持的格式)。

Gui2exe:http://code.google.com/p /gui2exe/downloads/detail?name=GUI2Exe_0.5.0.zip

示例:http ://code.google.com/p/gui2exe/wiki/GUI2ExeExamples

You can deal with py2exe and the headaches, I tried doing this, even when I had it right, it would error, though I did find the excellent python program gui2exe, this makes it extremely easy to make an exe (or any of the other supported formats).

Gui2exe: http://code.google.com/p/gui2exe/downloads/detail?name=GUI2Exe_0.5.0.zip

Examples: http://code.google.com/p/gui2exe/wiki/GUI2ExeExamples

祁梦 2024-10-02 03:55:37

从您的评论中,我看到您正在命令提示符中执行此操作:

setup.py py2exe 

来自 py2exe 教程第三步,你应该这样做(在命令 promt ):

python setup.py py2exe

再看一下原问题的评论,发现这个建议已经有人提出了。为此向华金+1。

尝试再次回答您的问题:Joaquin 还提到这可能是路径问题。您可能想考虑将 python 文件复制到 C:\Python 中,而不是尝试解决这个问题。然后在命令提示符中:

cd C:\Python
python setup.py py2exe

这一直对我有用

希望这有帮助

From your comments, I see that you are doing this in the command prompt:

setup.py py2exe 

from the py2exe tutorial's third step, you should be doing this instead (in the command promt):

python setup.py py2exe

A second look at the comments on the original question shows that this suggestion has already been made. +1 to joaquin to for this.

To try to answer your question again: Joaquin also mentioned that this might be a path issue. Rather than trying to fix that, you might want to consider the easier option of copying your python files into C:\Python. Then in the command prompt:

cd C:\Python
python setup.py py2exe

This has always worked for me

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文