pyinstaller和reportlab的问题 [英] Issues with pyinstaller and reportlab

查看:119
本文介绍了pyinstaller和reportlab的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Alright so I have a python project that I want to compile, so I decided to use pyinstaller (first time compiling python). Now it compiled fine but when I run the exe it returns -1. So after a bit of messing around I figured out that it was related to reportlab.platypus.

所以我的第一个直觉是检查使用钩子是否有任何改变,所以我尝试添加reportlab.pdfbase._fontdatareportlab.lib.utils钩子(这是我可以找到的与reportlab相关的唯一钩子文件).尽管付出了这些努力,但还是失败了.

So my first instinct was to check to see if using hooks changed anything, so I tried adding the reportlab.pdfbase._fontdata and reportlab.lib.utils hooks (these were the only hook files I could find related to reportlab). Despite this effort it still failed.

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

Here is the output when the exe is run from the terminal:

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行:

From this I gather that it crashes on running line 5 in "Board_builder.py" (the file that handles reportlab in my project) here are the first 5 lines of that file:

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意味着什么,非常欢迎任何建议!

I have no idea what the AttributeError it is throwing means, any advice would be very welcome!

推荐答案

好了,我能正常工作了,

Well I got it working,

决定去看看AttributeError的确切来源,所以我检查了reportlab/rl_config.pyreportlab/lib/utils.py文件,发现它正在递归地检查对象以查找目录(由rl_isdir暗示).与其他对象列表一起检查FrozenImporter卡住的方式

Decided to go look at where exactly the AttributeError was being thrown from so I inspected the reportlab/rl_config.py and reportlab/lib/utils.py files and found that it was checking objects recursively looking for directories (as insinuated by rl_isdir). Some how the FrozenImporter got stuck being checked with a list of other objects

所以我替换了这一行:

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

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

This may not have been the cleanest most efficient way to resolve the issue but it only touches one line of the original code so I found this to be the most straight forward solution.

这篇关于pyinstaller和reportlab的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆