pyinstaller编译的脚本由于缺少模块而崩溃

2024-09-29 23:27:49 发布

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

我试着在Mac上编译我的程序。后来我搬到了ubuntu,甚至不能正确编译hello world: 我写了最简单的hello world:

print("hello world")

然后尝试使用以下方法编译它:

^{pr2}$

一切似乎都很好,直到我试着运行它:

dist/hello

得到了以下回溯:

[2886] mod is NULL - structTraceback (most recent call last):
  File "/usr/lib/python3.6/struct.py", line 13, in <module>
    from _struct import *
ModuleNotFoundError: No module named '_struct'
[2886] mod is NULL - pyimod02_archiveTraceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/PyInstaller-3.4.dev0+g5f91905-py3.6.egg/PyInstaller/loader/pyimod02_archive.py", line 28, in <module>
    import struct
ModuleNotFoundError: No module named 'struct'
[2886] mod is NULL - pyimod03_importersTraceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/PyInstaller-3.4.dev0+g5f91905-py3.6.egg/PyInstaller/loader/pyimod03_importers.py", line 24, in <module>
    from pyimod02_archive import ArchiveReadError, ZlibArchiveReader
ModuleNotFoundError: No module named 'pyimod02_archive'
Traceback (most recent call last):
  File "PyInstaller-3.4.dev0+g5f91905-py3.6.egg/PyInstaller/loader/pyiboot01_bootstrap.py", line 15, in <module>
ModuleNotFoundError: No module named 'pyimod03_importers'
[2886] Failed to execute script pyiboot01_bootstrap

这看起来很奇怪,因为我没有显式地导入任何模块,但是我按照一个建议添加缺少的模块你好。规范在hiddenimports下。所以我补充道

hiddenimports=['_struct', 'struct', 'pyimod02_archive','pyimod03_importers']

试着用

pyinstaller --onefile hello.spec

但是当我试图运行exe文件时,得到了和以前完全相同的错误。在

我做错什么了? 我在ubuntu16.04.3上使用pyinstaller 3.4.dev0+g5f91905和python3.6.2


Tags: noinpymosthellolinecallstruct

热门问题