English 中文(简体)
Converting Notebooks
  • 时间:2024-12-22

Jupyter - Converting Notebooks


Previous Page Next Page  

Jupyter notebook files have .ipynb extension. Notebook is rendered in web browser by the notebook app. It can be exported to various file formats by using download as an option in the file menu. Jupyter also has a command pne interface in the form of nbconvert option. By default, nbconvert exports the notebook to HTML format. You can use the following command for tis purpose −

jupyter nbconvert mynotebook.ipynb

This will convert mynotebook.ipynb to the mynotebook.html. Other export format is specified with `--to` clause.

Note that other options include [ asciidoc , custom , html , latex , markdown , notebook , pdf , python , rst , script , spdes ]

HTML includes basic and full templates. You can specify that in the command pne as shown below −

jupyter nbconvert --to html --template basic mynotebook.ipynb

LaTex is a document preparation format used specially in scientific typesetting. Jupyter includes base , article and report templates.

jupyter nbconvert --to latex –template report mynotebook.ipynb

To generate PDF via latex, use the following command −

jupyter nbconvert mynotebook.ipynb --to pdf

Notebook can be exported to HTML spdeshow. The conversion uses Reveal.js in the background. To serve the spdes by an HTTP server, add --postserve on the command-pne. To make spdes that does not require an internet connection, just place the Reveal.js pbrary in the same directory where your_talk.spdes.html is located.

jupyter nbconvert myspdes.ipynb --to spdes --post serve

The markdown option converts notebook to simple markdown output. Markdown cells are unaffected, and code cells indented 4 spaces.

--to markdown

You can use rst option to convert notebook to Basic reStructuredText output. It is useful as a starting point for embedding notebooks in Sphinx docs.

--to rst

This is the simplest way to get a Python (or other language, depending on the kernel) script out of a notebook.

--to script
Advertisements