简体   繁体   English

如何在 Jupyter 上以 HTML 格式导出当前笔记本

[英]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

1 Save your Notebook in HTML format: 1 以 HTML 格式保存您的笔记本:

  1. 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 文件具有您的代码/笔记本的最新保存版本。

  2. 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.

相关问题 Jupyter-将当前ipynb文件导出到笔记本中的html - Jupyter - export current ipynb file to html within the notebook 如何从命令行将Jupyter笔记本导出为HTML? - How export a Jupyter notebook to HTML from the command line? 如何使用代码单元中的行号将 Jupyter Notebook 导出到 html - How to export Jupyter Notebook to html with line numbers in code cells 如何使用 TOC 和可折叠标题导出独立 (HTML) Jupyter 笔记本 - How to export standalone (HTML) Jupyter notebook with TOC and collapsible headers Jupyter Notebooks:如何将笔记本导出为 HTML,包括 splitcell 扩展? - Jupyter Notebooks: How to export a notebook to HTML including the splitcell extension? 如何帮助 Python 找到 Jupyter 命令“jupyter-nbconvert”,将 Jupyter Notebook 导出为 HTML? - How do I help Python find Jupyter command 'jupyter-nbconvert', to export Jupyter Notebook to HTML? 如何在 Jupyter Lab 的“将笔记本导出为...”菜单上获得“将笔记本导出为 Html_toc”选项? - How can I get the option 'Export Notebook to Html_toc' on the 'Export Notebook as…' menu in Jupyter Lab? 使用行号将 Jupyter 笔记本导出为 HTML? - Export Jupyter notebook to HTML with line numbers? "VSCode 无法将 jupyter notebook 导出到 html" - VSCode fails to export jupyter notebook to html VScode 无法将 Jupyter 笔记本导出到 HTML - 未找到“jupyter-nbconvert” - VScode fails to export Jupyter notebook to HTML - 'jupyter-nbconvert` not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM