pyinstaller和reportlab的问题

时间:2016-02-29 03:10:25

标签: python pyinstaller reportlab attributeerror

好吧所以我有一个我要编译的python项目,所以我决定使用pyinstaller(第一次编译python)。现在它编译得很好但是当我运行exe时它返回-1。因此,经过一番混乱,我发现它与reportlab.platypus有关。

所以我的第一直觉是检查是否使用了钩子改变了什么,所以我尝试添加reportlab.pdfbase._fontdatareportlab.lib.utils钩子(这些是我能找到的与reportlab相关的唯一钩子文件)。尽管如此,它仍然失败了。

以下是从终端运行exe时的输出:

Traceback (most recent call last):
  File "<string>", line 12, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
  File "C:\Users\Jon\Desktop\PyInstaller-3.1.1\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "Board_builder.py", line 5, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
  File "C:\Users\Jon\Desktop\PyInstaller-3.1.1\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\reportlab\platypus\__init__.py", line 7, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
  File "C:\Users\Jon\Desktop\PyInstaller-3.1.1\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\reportlab\platypus\flowables.py", line 32, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
  File "C:\Users\Jon\Desktop\PyInstaller-3.1.1\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\reportlab\lib\styles.py", line 28, in <module>
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
  File "C:\Users\Jon\Desktop\PyInstaller-3.1.1\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\reportlab\rl_config.py", line 131, in <module>
  File "site-packages\reportlab\rl_config.py", line 102, in _startUp
  File "site-packages\reportlab\lib\utils.py", line 695, in rl_isdir
AttributeError: 'FrozenImporter' object has no attribute '_files'
main returned -1

从此我收集说它在&#34; Board_builder.py&#34;中运行第5行时崩溃了。 (在我的项目中处理reportlab的文件)这里是该文件的前5行:

import subprocess
import datetime
from reportlab.lib.units import mm, inch
from reportlab.lib.pagesizes import legal, landscape
from reportlab.platypus import SimpleDocTemplate, Table

我不知道它抛出的AttributeError意味着什么,非常欢迎任何建议!

1 个答案:

答案 0 :(得分:2)

嗯,我让它运转了,

决定去看看究竟是什么引发了AttributeError所以我检查了reportlab/rl_config.pyreportlab/lib/utils.py文件,发现它正在以递归方式查找目录(正如{{1所暗示的那样) }})。一些如何使用其他对象列表检查FrozenImporter被卡住了

所以我换了一行:

rl_isdir

使用:

return len(list(filter(lambda x,pn=pn: x.startswith(pn),list(__loader__._files.keys()))))>0

这可能不是解决问题的最简洁最有效的方法,但它只涉及原始代码的一行,所以我发现这是最直接的解决方案。