我正在开发一个大型 python 项目,最后脚本由 PyInstaller 打包。上周我打包和运行我的应用程序没有遇到任何问题。这周我打包脚本时没有出现任何错误。然而,当我现在运行我的可执行文件时,我似乎遇到了一个相当普遍的错误,但来自一个奇怪的来源:
Traceback (most recent call last):
File "<string>", line 120, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 271, in load_module
exec(bytecode, module.__dict__)
File "/tmp/build/tmpDJZeLr/out00-PYZ.pyz/encodings", line 157, in <module>
AttributeError: 'module' object has no attribute 'register'
Run Code Online (Sandbox Code Playgroud)
我在我的代码中查找罪魁祸首,但我的项目中没有一个名为“注册”的属性/函数/等。我尝试在自己的代码中添加一些调试语句,但在弹出此错误之前,我的脚本中没有一个函数被调用。
然后我决定在 pyi_importers.py 中第 70 行附近添加一些打印语句:
sys.modules[fullname] = module
# Run the module code.
print module
print module.__dict__
print bytecode
exec(bytecode, module.__dict__)
Run Code Online (Sandbox Code Playgroud)
结果是:
<module 'encodings.aliases' from '/tmp/_MEIbDiUZq/encodings/aliases.pyc'>
{'__name__': 'encodings.aliases', '__file__': '/tmp/_MEIbDiUZq/encodings/aliases.pyc', '__loader__': <pyi_importers.FrozenImporter object at 0x7f1666fa0d10>, '__doc__': None, '__package__': 'encodings'}
<code object <module> …Run Code Online (Sandbox Code Playgroud)