在 sphinx 文档中嵌入 ipython notebook

embed ipython notebook in sphinx document

我正在为自己的项目编写 API 文档。 我发现这个很酷的 documentation (yt 项目) 直接使用 ipython notebook 来举例。当我查看他们在 bitbucket 上的文档 repo 时,一个相关的 rst 似乎很简单:

.. notebook:: An_example_notebook.ipynb

但是,当然,它对我不起作用。我不确定 "notebook" 是否是固有块类型。也许 'notebook' 块需要一个外部包。实际上,当我在 sphinx 文档中搜索 "notebook" 时,我得到的结果为零。

如果我能直接用我的笔记本(不用转换)来举例子,那会轻松很多。 但我无法弄清楚如何实现这一目标。

nbsphinx 是一个 Sphinx 扩展,它为 *.ipynb 文件提供源解析器。

安装 nbsphinx:

pip install nbsphinx --user

编辑您的 conf.py 并将 'nbsphinx' 添加到扩展程序。

编辑您的 index.rst 并将 *.ipynb 文件的名称添加到 toctree.

完成上述操作后,请关注此 Link

运行狮身人面像!