如何将 IPython 笔记本转换为 PDF 和 HTML? [英] How to convert IPython notebooks to PDF and HTML?

查看:24
本文介绍了如何将 IPython 笔记本转换为 PDF 和 HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想转换我的 ipython-notebooks 以打印它们,或者只是以 html 格式发送它们.我注意到已经有一个工具可以做到这一点,nbconvert.虽然我已经下载了它,但我不知道如何使用 nbconvert2.py 转换笔记本,因为 nbconvert 说它已被弃用.nbconvert2.py 说我需要一个配置文件来转换笔记本,它是什么?是否存在有关此工具的文档?

I want to convert my ipython-notebooks to print them, or simply send them in html format. I have noticed that there exists a tool to do that already, nbconvert. Although I have downloaded it, I have no idea how to convert the notebook, with nbconvert2.py since nbconvert says that it is deprecated. nbconvert2.py says that I need a profile to convert the notebook, what is it? Does there exist a documentation about this tool?

推荐答案

如果您安装了 LaTeX,您可以使用 File 直接从 Jupyter notebook 下载 PDF 格式 ->下载为 ->通过 LaTeX (.pdf) 生成的 PDF.否则按照这两个步骤.

If you have LaTeX installed you can download as PDF directly from Jupyter notebook with File -> Download as -> PDF via LaTeX (.pdf). Otherwise follow these two steps.

  1. 对于 HTML 输出,您现在应该使用 Jupyter 代替 IPython 并选择 File ->下载为 ->HTML (.html) 或运行以下命令:

  1. For HTML output, you should now use Jupyter in place of IPython and select File -> Download as -> HTML (.html) or run the following command:

 jupyter nbconvert --to html notebook.ipynb  

这会将 Jupyter 文档文件 notebook.ipynb 转换为 html 输出格式.

This will convert the Jupyter document file notebook.ipynb into the html output format.

Google Colaboratory 是 Google 的免费 Jupyter 笔记本环境,无需设置并完全在云端运行.如果您使用的是 Google Colab,命令是相同的,但 Google Colab 只允许您下载 .ipynb 或 .py 格式.

Google Colaboratory is Google's free Jupyter notebook environment that requires no setup and runs entirely in the cloud. If you are using Google Colab the commands are the same, but Google Colab only lets you download .ipynb or .py formats.

将 html 文件 notebook.html 转换为名为 notebook.pdf 的 pdf 文件.在 Windows、macOS(brew install wkhtmltodf)或 Linux 中,安装 wkhtmltopdf.wkhtmltopdf 是一个命令行实用程序,用于使用 WebKit 将 html 转换为 pdf.您可以从链接的网页下载 wkhtmltopdf,或者在许多 Linux 发行版中可以在他们的存储库中找到它.

Convert the html file notebook.html into a pdf file called notebook.pdf. In Windows, macOS (brew install wkhtmltodf) or Linux, install wkhtmltopdf. wkhtmltopdf is a command line utility to convert html to pdf using WebKit. You can download wkhtmltopdf from the linked webpage, or in many Linux distros it can be found in their repositories.

 wkhtmltopdf notebook.html notebook.pdf   


原始(现在几乎已过时)修订版:将 IPython 笔记本文件转换为 html.

ipython nbconvert --to html notebook.ipynb

这篇关于如何将 IPython 笔记本转换为 PDF 和 HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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