【问题标题】:Convert python script outputs to pdf just like jupyter notebook像 jupyter notebook 一样将 python 脚本输出转换为 pdf
【发布时间】:2019-12-31 06:29:48
【问题描述】:

我一直在寻找类似的东西:

!jupyter nbconvert File.ipynb --no-input --to pdf

只是我不能在生产环境中使用jupyter,所以我必须将其转换为脚本,然后使用该脚本生成pdf。 此外,输入不应显示在 pdf 文件中,而应仅显示在输出中。 我们在普通的python中有这样的东西吗?

我有 N 行用 jupyter 编写,我希望这些代码行的输出为 pdf 格式。喜欢报告

【问题讨论】:

  • 你可以看看Code2pdf
  • @AnoopRDesai 谢谢,但它没有任何选项来禁止在 pdf 中输入
  • 我不想在 pdf 中包含输入
  • 您可以将logger 与日志文件一起使用为.pdf docs.python.org/2.6/library/logging.html
  • @MohamedThasinah 它也没有任何选项不允许在 pdf 中显示输入

标签: python pandas pdf jupyter-notebook


【解决方案1】:

您可以将其用作 Ploomber 管道 (https://github.com/ploomber/ploomber),它会帮助您自动将笔记本转换为输出。例如,如果您编辑扩展名,您的笔记本的输出可以是 pdf,或者是 HTML 报告/python/notebook 脚本。您可以轻松地从单个命令开始,定义一次(在 yaml 中),然后它将成为您的项目/笔记本的骨架。

下面是它的样子:

tasks:   # also works with .ipynb etc
  - source: output-to-pdf.py
    product:
      nb: output/1-get.ipynb
      data: output/output-report.pdf

要执行工作流:

ploomber build

它还可以自动设置 conda/virtualenv,假设你有一个 requirements.txt:

ploomber install

ploomber build

【讨论】:

    猜你喜欢
    • 2019-11-23
    • 2019-03-05
    • 1970-01-01
    • 2018-04-25
    • 1970-01-01
    • 1970-01-01
    • 2015-11-17
    • 1970-01-01
    • 2019-03-26
    相关资源
    最近更新 更多