我已经尝试在我的Mac上编译Python程序,一切顺利。然后我转移到ubuntu,甚至无法正确编译hello world: 我写了最简单的你好世界:
print("hello world")
然后尝试使用以下方法编译它:
pyinstaller --onefile hello.py
一切似乎都很好,直到我尝试运行它:
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下的hello.spec中添加缺少的模块。所以我添加了
hiddenimports=['_struct', 'struct', 'pyimod02_archive','pyimod03_importers']
并尝试使用
进行编译pyinstaller --onefile hello.spec
但是当我尝试运行exe文件时,得到了与以前完全相同的错误。
我做错了什么? 我在Ubuntu 16.04.3上使用pyinstaller 3.4.dev0 + g5f91905和Python 3.6.2