PyInstaller:AttributeError'module'对象没有属性'register'

时间:2015-02-24 21:19:31

标签: python pyinstaller attributeerror

我正在开发一个大型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'

我在我的代码中查找罪魁祸首,但在我的项目中没有任何地方有一个名为&#39; register&#39;的属性/函数/等。我试图在我自己的代码中添加一些调试语句,但是在弹出此错误之前,我的脚本中没有一个函数会被调用。

然后我决定在第70行附近的pyi_importers.py中添加一些打印语句:

            sys.modules[fullname] = module
            # Run the module code.
            print module
            print module.__dict__
            print bytecode
            exec(bytecode, module.__dict__)

结果是:

<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> at 0x7f1666fb4f30, file "/tmp/build/tmpg_2pIX/out00-PYZ.pyz/encodings.aliases", line 17>
Traceback (most recent call last):...

我环顾四周,发现编码.aliases与内置的python库有关。我使用的是Python 2.7.6和PyInstaller 2.1;哪个应该根据他们的文档兼容。我在云基础IDE(c9)中工作,但似乎不应该是问题,因为这是一个python而不是操作系统问题。

我很难过。有什么帮助吗?

1 个答案:

答案 0 :(得分:4)

问题在于包名冲突。在我的项目中有一个名为“codecs”的包。当PyInstaller正在处理python标准库钩子时,我的项目的命名空间胜过了Python标准库。反过来,这导致encodings.aliases模块导入我的项目的编解码器模块而不是编码模块。