我正在使用 py2exe
将我的脚本编译成一个可在 Windows 上运行的 exe 文件,但是由于我的操作系统是 Windows 7 x64,因此遇到了错误。 我正在使用以下脚本在 cmd 中运行 execmaker.py py2exe
:
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,安装的是 Python 2.7.5 的 64 位版本。当我 cd
到 execmaker.py
和 My_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 位 Windows 上运行 32 位 python。所以基本上,无论是 32 位还是 64 位 python 都无法工作,因为我正在运行 64 位 Windows。是否有解决办法,或者我需要在 32 位机器上安装 python 和所有我一直在使用的模块来进行编译?
编辑:我进行了更多的研究,并没有任何结果。目前,除非这个问题得到更有效的解答,否则我想在一个分区或通过 Parallels(这是我做的方式)上安装一个 32 位操作系统。
python execmaker.py py2exe
。我发现有时候其他 Python 脚本的结果在显式调用解释器和让 Windows 的文件关联处理之间存在差异。 - martineau