用 pyinstaller 把 Python 文件生成 exe 文件后,打开 exe 文件时报错“不是有效的 win32 应用程序”,怎么解决呢? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
scb20100708

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

  •  
  •   scb20100708 Nov 5, 2017 4695 views
    This topic created in 3096 days ago, the information mentioned may be changed or developed.
    想把 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
    8 replies    2017-11-06 19:00:43 +08:00
    takanasi
        1
    takanasi  
       Nov 5, 2017   1
    wdlth
        2
    wdlth  
       Nov 5, 2017
    可以检查有没有安装相关的 VC++运行库
    weyou
        3
    weyou  
       Nov 5, 2017 via Android   1
    用命令: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
        4
    redapple0204  
       Nov 5, 2017
    你的 python 版本是 x64 的吧,换成 x86 的
    redapple0204
        5
    redapple0204  
       Nov 5, 2017
    哦对了,还有一点,xp 最高支持 python3.4,所以说你生成 exe 的电脑上的 python 版本必须要小于 3.4
    scb20100708
        6
    scb20100708  
    OP
       Nov 6, 2017
    @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
        7
    weyou  
       Nov 6, 2017
    @scb20100708 dumpbin 要安装了 VS 之后才有。其实 exescope 之类的任何 PE 文件 explorer 都是可以显示这个信息的。

    这个问题之前遇见过,应该就是 Operation system version 的问题,你可以直接重新编译 pyinstaller 的 bootloader 解决。
    scb20100708
        8
    scb20100708  
    OP
       Nov 6, 2017
    @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 了,谢谢帮助
    About     Help     Advertise     Blog     API     FAQ     Solana     3361 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 33ms UTC 12:51 PVG 20:51 LAX 05:51 JFK 08:51
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86