[英]How to export current notebook in HTML on Jupyter
如何将当前笔记本(从笔记本本身内部,使用Python )导出到 HTML(到自定义输出路径)?
By looking at nbconvert docs , you'll see that you can use --to html method:通过查看nbconvert docs ,您会发现可以使用--to html方法:
import os
os.system('jupyter nbconvert --to html yourNotebook.ipynb')
This will create a yourNotebook.html
file inside yourNotebook.ipynb
folder.这将在
yourNotebook.ipynb
文件夹中创建一个yourNotebook.html
文件。
You can do it.你能行的。 Use the following very simple steps:
使用以下非常简单的步骤:
I am using: OS: Ubuntu, Anaconda-Jupyter notebook, Python 3我正在使用:操作系统:Ubuntu、Anaconda-Jupyter notebook、Python 3
Start the jupyter notebook that you want to save in HTML format.启动要以 HTML 格式保存的 jupyter 笔记本。 First save the notebook properly so that HTML file will have a latest saved version of your code/notebook.
首先正确保存笔记本,以便 HTML 文件具有您的代码/笔记本的最新保存版本。
Run the following command from the notebook itself:从笔记本本身运行以下命令:
!jupyter nbconvert --to html your_notebook_name.ipynb
Edit: or you can also use: !jupyter nbconvert your_notebook_name.ipynb --to html
编辑:或者你也可以使用:
!jupyter nbconvert your_notebook_name.ipynb --to html
After execution will create HTML version of your notebook and will save it in the current working directory.执行后将创建笔记本的 HTML 版本并将其保存在当前工作目录中。 You will see one html file will be added into the current directory with
your_notebook_name.html
name您将看到一个 html 文件将添加到当前目录中,名称为
your_notebook_name.html
( your_notebook_name.ipynb
--> your_notebook_name.html
). (
your_notebook_name.ipynb
--> your_notebook_name.html
)。
If you want to know how to save it into pdf format please check my answer on this question as well: IPython notebook - unable to export to pdf如果您想知道如何将其保存为 pdf 格式,请查看我对这个问题的回答: IPython notebook - 无法导出为 pdf
Actually you need to save your notebook first, then you can use the nbconvert command其实你需要先保存你的笔记本,然后你可以使用 nbconvert 命令
It would be something like:它会是这样的:
%%javascript
IPython.notebook.save_notebook()
And Then进而
import os
os.system('jupyter nbconvert --to html yourNotebook.ipynb')
If you do not do this, it will not convert the actual notebook.如果你不这样做,它不会转换实际的笔记本。
The above answer yields the result .ipynb to .html.上面的答案将结果 .ipynb 生成为 .html。 But it exports .html file without output.
但它导出 .html 文件而没有输出。 In addition, if you want .html file with output, please use also
--execute
.此外,如果您想要带有输出的 .html 文件,请同时使用
--execute
。
jupyter nbconvert --execute --to html notebook.ipynb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.