在Windows 7 x64上使用py2exe编译时出现问题

2024-06-16 11:44:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用py2exe将脚本编译成一个exe文件以在Windows上运行,但我遇到了基于操作系统(Window 7 x64)的错误。我正在使用execmaker.py py2exe在cmd中运行以下脚本:

from distutils.core import setup
import py2exe

includes = []
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
            'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
            'Tkconstants', 'Tkinter']
packages = []
dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll',
                'tk84.dll']

setup(
    options = {"py2exe": {"compressed": 2, 
                          "optimize": 2,
                          "includes": includes,
                          "excludes": excludes,
                          "packages": packages,
                          "dll_excludes": dll_excludes,
                          "bundle_files": 1,
                          "dist_dir": "dist",
                          "xref": False,
                          "skip_archive": False,
                          "ascii": False,
                          "custom_boot_script": '',
                         }
              },
    windows=['My_Script.py'] #this is the name of the script I'm compiling to exe

(第页)

我编译成exe的实际脚本并不重要,因为当我使用bundle_files: 3,编译它时,它工作得非常好,它不捆绑任何文件,并将~200个.pyo文件留在一个文件夹中。

所以让我们进入问题的中心:在Win 7 x64上,我安装了64位版本的Python 2.7.5。当我cd找到execmaker.pyMy_Script.py文件所在的文件,并在cmd(execmaker.py py2exe)中运行它时,会收到一条错误消息,其内容如下: error: bundle-files 1 is not yet supported on win64,我认为这意味着它不会捆绑文件,因为我的操作系统是64位的。我想这可能是因为我安装了64位python而产生的问题,但是当我卸载它时,我收到了错误DLL load failed: %1 is not a valid Win32 application.

DLL加载错误是由在64位窗口上运行32位python引起的。所以基本上,它不适用于32位或64位python,因为我运行的是64位Windows。是否有解决方法,或者我需要安装python和我在32位计算机上使用的所有模块来进行编译?

谢谢你的帮助,也谢谢你在这个很长的问题上对我的支持。

编辑-解决方案:我做了更多的研究,却什么也没想到。现在,除非用更有效的方法来回答这个问题,否则在一个分区上或通过并行程序(我就是这样做的)安装32位操作系统就足够了。


Tags: 文件py脚本falsepackages错误filesexe
3条回答

我也在Windows7上运行这个应用程序。如果可以,卸载python 2.7x64,重新安装python2.7x86,最后安装py2exe。这为我解决了这个问题。

我想现在对你来说已经太晚了,但是对于困在这条船上的下一个灵魂来说,在我看来,一个更有效的方法是从oracle免费安装virtualbox(vb),然后在上面安装32位操作系统。这样你就不必分割你的硬盘或其他什么,你可以没有任何风险卸载vb就像任何其他程序一样。

另一个选择是尝试使用pyinstaller。我只使用它来为linux系统生成可执行文件,但我认为您也可以在windows上使用它。

我遇到了与OP类似的问题:在64位Windows 7 Python2.7环境中,一个python应用程序与Py2exe捆绑在一起,在32位W7下运行了一段时间。2013年8月初,它仍然有效。2013年11月下旬,发现它因版本冲突而停止工作。我最好的猜测是,这两个日期之间的Windows更新导致了更严格的版本检查。

我在旧的32位Vista Python27开发机器上重新绑定了这个应用程序和Py2Exe,它在64位和32位Windows下都能正常工作。

这个答案(来自here)对我很有帮助:

The easiest thing to do though is just to make sure that your 64-bit Windows installation is using a 32-bit Python installation. py2exe doesn't really build anything; it just bundles your source files up with the Python interpreter, so as long as that interpreter is 32-bit the generated exes should be able to run on either platform.

为了完整起见,这是一条错误消息:

"This version of [module name] is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need a x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher."

相关问题 更多 >