Python:使用 Pyinstaller 编译

Posted

技术标签:

【中文标题】Python:使用 Pyinstaller 编译【英文标题】:Python: Compiling with Pyinstaller 【发布时间】:2011-04-03 19:05:05 【问题描述】:

所以我正在尝试使用 Pyinstaller 创建一个可执行的二进制文件。在构建文件“warnpython.txt”时出现此消息。

W: no module named msvcrt (conditional import by subprocess)
W: no module named msvcrt (delayed import by getpass)
W: no module named rourl2path (conditional import by urllib)
W: no module named msvcrt (conditional import by getpass)
W: no module named _subprocess (conditional import by subprocess)
W: no module named AES (delayed, conditional import by archive)
W: no module named _scproxy (conditional import by urllib)
W: no module named org (top-level import by pickle)
W: no module named EasyDialogs (conditional import by getpass)
W: no module named SOCKS (top-level import by ftplib)
W: no module named _winreg (delayed import by urllib)
W: no module named nt (top-level import by ntpath)
W: no module named org (top-level import by copy)
W: no module named _emx_link (conditional import by os)
W: __all__ is built strangely at line 0 - __future__ (/usr/lib/python2.6/__future__.pyc)
W: __all__ is built strangely at line 0 - collections (/usr/lib/python2.6/collections.pyc)
W: delayed  exec statement detected at line 0 - collections (/usr/lib/python2.6/collections.pyc)
W: delayed  __import__ hack detected at line 0 - email (/usr/lib/python2.6/email/__init__.pyc)
W: delayed  __import__ hack detected at line 0 - encodings (/usr/lib/python2.6/encodings/__init__.pyc)
W: delayed  __import__ hack detected at line 0 - optparse (/usr/lib/python2.6/optparse.pyc)
W: delayed  exec statement detected at line 0 - socket (/usr/lib/python2.6/socket.pyc)
W: delayed conditional __import__ hack detected at line 0 - doctest (/usr/lib/python2.6/doctest.pyc)
W: delayed  exec statement detected at line 0 - doctest (/usr/lib/python2.6/doctest.pyc)
W: delayed conditional __import__ hack detected at line 0 - doctest (/usr/lib/python2.6/doctest.pyc)
W: __all__ is built strangely at line 0 - dis (/usr/lib/python2.6/dis.pyc)
W: delayed  eval hack detected at line 0 - os (/usr/lib/python2.6/os.pyc)
W: delayed conditional __import__ hack detected at line 0 - unittest (/usr/lib/python2.6/unittest.pyc)
W: delayed conditional __import__ hack detected at line 0 - unittest (/usr/lib/python2.6/unittest.pyc)
W: __all__ is built strangely at line 0 - tokenize (/usr/lib/python2.6/tokenize.pyc)
W: delayed  exec statement detected at line 0 - bdb (/usr/lib/python2.6/bdb.pyc)
W: delayed  eval hack detected at line 0 - bdb (/usr/lib/python2.6/bdb.pyc)
W: delayed  eval hack detected at line 0 - bdb (/usr/lib/python2.6/bdb.pyc)
W: delayed  __import__ hack detected at line 0 - pickle (/usr/lib/python2.6/pickle.pyc)
W: delayed  __import__ hack detected at line 0 - pickle (/usr/lib/python2.6/pickle.pyc)
W: delayed conditional exec statement detected at line 0 - iu (/home/zack/Desktop/pyinstaller-1.5-rc1/iu.pyc)
W: delayed conditional exec statement detected at line 0 - iu (/home/zack/Desktop/pyinstaller-1.5-rc1/iu.pyc)
W: delayed  eval hack detected at line 0 - gettext (/usr/lib/python2.6/gettext.pyc)
W: delayed conditional eval hack detected at line 0 - warnings (/usr/lib/python2.6/warnings.pyc)
W: delayed conditional __import__ hack detected at line 0 - warnings (/usr/lib/python2.6/warnings.pyc)
W: delayed  exec statement detected at line 0 - pdb (/usr/lib/python2.6/pdb.pyc)
W: delayed conditional eval hack detected at line 0 - pdb (/usr/lib/python2.6/pdb.pyc)
W: delayed  eval hack detected at line 0 - pdb (/usr/lib/python2.6/pdb.pyc)
W: delayed conditional eval hack detected at line 0 - pdb (/usr/lib/python2.6/pdb.pyc)
W: delayed  eval hack detected at line 0 - pdb (/usr/lib/python2.6/pdb.pyc)

在执行新制作的可执行文件后,我立即被退回到终端,就好像进程已经退出一样。当通过执行 py 脚本进行测试时,一切正常,只有在使用 Pyinstaller 编译时才会发生这种情况。警告文件是否给了我们任何线索?

【问题讨论】:

这不是答案,但 cx_Freeze 可能是适合您的替代品:cx-freeze.sourceforge.net 老问题,但仅用于文档:您应该激活调试模式,看看它运行得有多糟糕,有关详细信息,请参阅***.com/questions/7879465/…。 【参考方案1】:

您的系统中似乎缺少模块 pywin32。尝试安装 ActivePython 或安装 pywin32 模块。

http://python.net/crew/mhammond/win32/Downloads.html

【讨论】:

以上是关于Python:使用 Pyinstaller 编译的主要内容,如果未能解决你的问题,请参考以下文章

Python学习使用Pyinstaller将py文件导出为exe文件

使用PyInstaller构建Cython编译的python代码。

使用 PyInstaller 编译 PyQt5 Python 应用程序时遇到问题

Python 脚本在定期运行时工作正常,但在使用 PyInstaller 编译时不能正常运行

使用 pyinstaller 编译 python 脚本后没有名为 'scipy.spatial.transform._rotation_groups 的模块

如何使用 pyinstaller 将多个子进程 python 文件编译成单个 .exe 文件