Pyinstaller使用matplotlib和reportlab生成PDF

时间:2016-03-03 23:52:28

标签: python pdf matplotlib pyinstaller reportlab

我有一个代码,它使用reportlab生成表格和matplotlib来生成图形,然后将它们保存为PDF文件。当我通过命令行运行脚本时,它工作正常,但每次我使用pyinstaller转换.exe时,文件都拒绝运行。我已经尝试指定钩子的路径,但这似乎什么都不做。我认为问题与创建新的PDF文件有关,但exe文件没有运行,我不知道如何解决这个问题。

from reportlab.lib import colors
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle
import matplotlib.pyplot as plt

doc = SimpleDocTemplate('sample.pdf', pagesize=letter)
# container for the 'Flowable' objects
elements = []
data = [[1, 2, 3], [4, 5, 6]]
t=Table(data)
t.setStyle(TableStyle([ ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
                        ('BOX', (0,0), (-1,-1), 0.25, colors.black),
                        ('BACKGROUND',(0,0),(-1,0),colors.lightgreen),
                        ('BACKGROUND', (0,1),(-1,1),colors.lightblue),]))
elements.append(t)
# write the document to disk
doc.build(elements)

plt.plot(data[0], data[1])
plt.savefig('Figure.pdf')
plt.show()

我尝试在命令行上运行test.exe(我的文件名),现在我收到此错误。

Traceback (most recent call last):
  File "<string>", line 3, 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:\pyfolder\continuum\lib\site-packages\PyInstaller\loader\pyimod03_impo
rters.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:\pyfolder\continuum\lib\site-packages\PyInstaller\loader\pyimod03_impo
rters.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:\pyfolder\continuum\lib\site-packages\PyInstaller\loader\pyimod03_impo
rters.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:\pyfolder\continuum\lib\site-packages\PyInstaller\loader\pyimod03_impo
rters.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'

0 个答案:

没有答案