embed ipython notebook in sphinx document

  • Last Update :
  • Techknowledgy :

To Install nbsphinx:

pip install nbsphinx--user

Suggestion : 2

MyST-NB allows embedding Python objects coming from the notebook in the documentation (read their “glue” documentation for more information) and provides more sophisticated error reporting than the one nbsphinx has.,Jupyter notebooks are a popular tool to describe computational narratives that mix code, prose, images, interactive components, and more. Embedding them in your Sphinx project allows using these rich documents as documentation, which can provide a great experience for tutorials, examples, and other types of technical content. There are a few extensions that allow integrating Jupyter and Sphinx, and this document will explain how to achieve some of the most commonly requested features.,nbsphinx provides functionality to create thumbnail galleries, whereas MyST-NB does not have such functionality at the moment (see Creating galleries of examples using notebooks for more information about galleries).,The classical Jupyter Notebook interface provides a “Save Notebook Widget State” action in the “Widgets” menu, as explained in the ipywidgets documentation. You need to click it before exporting your notebook to HTML.

extensions = [
   "nbsphinx",
]
extensions = [
   "myst_nb",
]
..toctree::
   : maxdepth: 2: caption: Contents:

   notebooks / Example 1
``
`{toctree}
---
maxdepth: 2
caption: Contents:
---
notebooks/Example 1
`
``
-- -
jupytext:
   text_representation:
   extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.10 .3
kernelspec:
   display_name: Python 3
language: python
name: python3
   -- -

   # Plain - text notebook formats

This is a example of a Jupyter notebook stored in MyST Markdown format.

``
`{code-cell} ipython3
import sys
print(sys.version)
`
``

``
`{code-cell} ipython3
from IPython.display import Image
`
``

``
`{code-cell} ipython3
Image("http://sipi.usc.edu/database/preview/misc/4.2.03.png")
`
``
nbsphinx_custom_formats = {
   ".md": ["jupytext.reads", {
      "fmt": "mystnb"
   }],
}

Suggestion : 3

Jupyter Book uses Sphinx for almost everything that it does. For example - resolving cross-references, generating HTML or PDFs, reading in source files and Jupyter Notebooks, etc. It accomplishes this via activating a number of Sphinx Extensions that the Executable Books Team has created. These extensions grow Sphinx’s capabilities so that it can handle the use-cases of Jupyter Book.,To understand how Jupyter Book configures Sphinx, you should check out the config.py module. For example, here is the line that defines the default Sphinx configuration.,Beyond having a few extensions pre-activated, there are a couple of other ways that Jupyter Book differs from Sphinx.,Because most of Jupyter Book’s functionality comes from Sphinx extensions, it means that the broader Sphinx community can replicate much of the functionality of Jupyter Book. You might want to do this if you want more control over the build process or need to integrate more complex steps into your build process.

jupyter - book config sphinx path / to / mybook /