ValueError:在Reportlab python中用故事构建文档时

2024-04-25 01:49:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在与reportlab合作,在机器学习过程之后创建一个自动报告。它确实在windows上创建了一个完美的报告。但是,当我试图把我的工作放在一个远程服务器上时,一切都会完美地工作到文档生成(故事)“东西

File "train_prediction.py", line 551, in create_pdfdoc pdf_doc.build(story) File "/home/adservio/periosystem/perio-env/lib64/python3.6/site-packages/reportlab/platypus/doctemplate.py", line 1038, in build self.handle_flowable(flowables) File "/home/adservio/periosystem/perio-env/lib64/python3.6/site-packages/reportlab/platypus/doctemplate.py", line 892, in handle_flowable if frame.add(f, canv, trySplit=self.allowSplitting): File "/home/adservio/periosystem/perio-env/lib64/python3.6/site-packages/reportlab/platypus/frames.py", line 167, in _add w, h = flowable.wrap(aW, h) File "/home/adservio/periosystem/perio-env/lib64/python3.6/site-packages/reportlab/platypus/flowables.py", line 495, in wrap return self.drawWidth, self.drawHeight File "/home/adservio/periosystem/perio-env/lib64/python3.6/site-packages/reportlab/platypus/flowables.py", line 489, in getattr self._setup_inner() File "/home/adservio/periosystem/perio-env/lib64/python3.6/site-packages/reportlab/platypus/flowables.py", line 457, in _setup_inner self.drawWidth = width or self.imageWidth ValueError: The truth va lue of an array with more than one element is ambiguous. Use a.any() or a.all()

def create_pdfdoc(pdfdoc, story):
"""
Creates PDF doc from story.
"""
pdf_doc = BaseDocTemplate(pdfdoc, pagesize = PAGE_SIZE,
    leftMargin = MARGIN_SIZE, rightMargin = MARGIN_SIZE,
    topMargin = MARGIN_SIZE, bottomMargin = MARGIN_SIZE)
main_frame = Frame(MARGIN_SIZE, MARGIN_SIZE,
    PAGE_SIZE[0] - 2 * MARGIN_SIZE, PAGE_SIZE[1] - 2 * MARGIN_SIZE,
    leftPadding = 0, rightPadding = 0, bottomPadding = 0,
    topPadding = 0, id = 'main_frame')
main_template = PageTemplate(id = 'main_template', frames = [main_frame])
pdf_doc.addPageTemplates([main_template])

pdf_doc.build(story)

Tags: inpymarginselfenvhomesizeline