gpt4 book ai didi

python - pyinstaller 和 reportlab 的问题

转载 作者:行者123 更新时间:2023-12-01 04:05:25 25 4
gpt4 key购买 nike

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

所以我的第一 react 是检查使用钩子(Hook)是否改变了任何东西,所以我尝试添加 reportlab.pdfbase._fontdatareportlab.lib.utils 钩子(Hook)(这些是我能找到的与reportlab相关的唯一 Hook 文件)。尽管做出了这些努力,但仍然失败了。

以下是从终端运行 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

据此我了解到它在“Board_builder.py”(在我的项目中处理reportlab的文件)中运行第5行时崩溃,这是该文件的前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 意味着什么,非常欢迎任何建议!

最佳答案

嗯,我已经成功了,

决定去看看 AttributeError 到底是从哪里抛出的,所以我检查了 reportlab/rl_config.pyreportlab/lib/utils.py 文件并发现它正在递归地检查对象以查找目录(如 rl_isdir 所暗示的那样)。 FrozenImporter 如何在检查其他对象列表时卡住的一些情况

所以我更换了该行:

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

与:

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

这可能不是解决问题的最干净、最有效的方法,但它只涉及原始代码的一行,因此我发现这是最直接的解决方案。

关于python - pyinstaller 和 reportlab 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35691320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com