用 pyinstaller 把 Python 文件生成 exe 文件后,打开 exe 文件时报错“不是有效的 win32 应用程序”,怎么解决呢?

2017-11-05 20:38:24 +08:00
 scb20100708
想把 hello.py 变成 exe 文件,结果在 winXP 32 位系统下总失败,

warnhello.txt 的内容是:

missing module named resource - imported by posix, D:\我的文档\Downloads\pyinstaller-pyinstaller-v3.3-12-g133d181\pyinstaller-pyinstaller-133d181\hello.py
missing module named posix - imported by os, D:\我的文档\Downloads\pyinstaller-pyinstaller-v3.3-12-g133d181\pyinstaller-pyinstaller-133d181\hello.py
missing module named _posixsubprocess - imported by subprocess, D:\我的文档\Downloads\pyinstaller-pyinstaller-v3.3-12-g133d181\pyinstaller-pyinstaller-133d181\hello.py
missing module named 'org.python' - imported by pickle, D:\我的文档\Downloads\pyinstaller-pyinstaller-v3.3-12-g133d181\pyinstaller-pyinstaller-133d181\hello.py, xml.sax
missing module named ce - imported by os, D:\我的文档\Downloads\pyinstaller-pyinstaller-v3.3-12-g133d181\pyinstaller-pyinstaller-133d181\hello.py
missing module named readline - imported by cmd, code, pdb, D:\我的文档\Downloads\pyinstaller-pyinstaller-v3.3-12-g133d181\pyinstaller-pyinstaller-133d181\hello.py
excluded module named _frozen_importlib - imported by importlib, D:\我的文档\Downloads\pyinstaller-pyinstaller-v3.3-12-g133d181\pyinstaller-pyinstaller-133d181\hello.py
missing module named _scproxy - imported by urllib.request
missing module named java - imported by platform, D:\我的文档\Downloads\pyinstaller-pyinstaller-v3.3-12-g133d181\pyinstaller-pyinstaller-133d181\hello.py
missing module named 'java.lang' - imported by platform, D:\我的文档\Downloads\pyinstaller-pyinstaller-v3.3-12-g133d181\pyinstaller-pyinstaller-133d181\hello.py, xml.sax._exceptions
missing module named vms_lib - imported by platform, D:\我的文档\Downloads\pyinstaller-pyinstaller-v3.3-12-g133d181\pyinstaller-pyinstaller-133d181\hello.py
missing module named termios - imported by tty, D:\我的文档\Downloads\pyinstaller-pyinstaller-v3.3-12-g133d181\pyinstaller-pyinstaller-133d181\hello.py, getpass
missing module named _dummy_threading - imported by dummy_threading, D:\我的文档\Downloads\pyinstaller-pyinstaller-v3.3-12-g133d181\pyinstaller-pyinstaller-133d181\hello.py
missing module named grp - imported by tarfile, shutil, D:\我的文档\Downloads\pyinstaller-pyinstaller-v3.3-12-g133d181\pyinstaller-pyinstaller-133d181\hello.py
missing module named pwd - imported by posixpath, tarfile, shutil, http.server, webbrowser, D:\我的文档\Downloads\pyinstaller-pyinstaller-v3.3-12-g133d181\pyinstaller-pyinstaller-133d181\hello.py, getpass
missing module named org - imported by copy, D:\我的文档\Downloads\pyinstaller-pyinstaller-v3.3-12-g133d181\pyinstaller-pyinstaller-133d181\hello.py
3773 次点击
所在节点    Python
8 条回复
takanasi
2017-11-05 21:02:46 +08:00
wdlth
2017-11-05 21:08:06 +08:00
可以检查有没有安装相关的 VC++运行库
weyou
2017-11-05 21:44:47 +08:00
用命令:dumpbin /header hello.exe
如果结果显示 operation system version 是 6.0, 这是表示此 pe 文件不兼容 xp,参考 https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx, 你可以重新编译 pyinstaller 的 bootloader。
redapple0204
2017-11-05 21:46:09 +08:00
你的 python 版本是 x64 的吧,换成 x86 的
redapple0204
2017-11-05 21:47:16 +08:00
哦对了,还有一点,xp 最高支持 python3.4,所以说你生成 exe 的电脑上的 python 版本必须要小于 3.4
scb20100708
2017-11-06 15:21:51 +08:00
@takanasi
用 cx_Freeze 方法可行
@wdlth
安装 win sdk 后仍报同样的错。
@weyou
用 dumpbin 命令后,提示“'dumpbin' 不是内部或外部命令,也不是可运行的程序”,按网上的办法找到 VCVARS32.BAT 在命令行中运行时又报错“ ERROR: Cannot determine the location of the VS Common Tools folder.”试了改 VCVARS32.BAT 内容的办法无用后便未继续弄,换别的方法了。
@redapple0204
python 版本:Python 3.4.0 (v3.4.0:04f714765c13, Mar 16 2014, 19:24:06) [MSC v.1600 32 bit (Intel)] on win32
weyou
2017-11-06 15:55:58 +08:00
@scb20100708 dumpbin 要安装了 VS 之后才有。其实 exescope 之类的任何 PE 文件 explorer 都是可以显示这个信息的。

这个问题之前遇见过,应该就是 Operation system version 的问题,你可以直接重新编译 pyinstaller 的 bootloader 解决。
scb20100708
2017-11-06 19:00:43 +08:00
@weyou
我按照 http://pythonhosted.org/PyInstaller/bootloader-building.html 编译 pyinstaller 的 bootloader 时报错:
File "./waf", line 3
Thomas Nagy , 2005-2016
^
SyntaxError: invalid syntax
查了下好像是我现在用的 python 版本(Python 3.4.0)的问题,已找到转 exe 的办法了,不继续试 pyInstaller 了,谢谢帮助

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/403754

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX