Jupyter笔记本不使用sphinx渲染

2024-04-29 13:14:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用sphinx来记录一个python项目。我想添加一些教程作为*.ipynb。 我有一个关于如何渲染jupyter笔记本的问题。这是我的密码

我创建了一个docs文件夹,所有sphinx命令都将在此文件夹下运行。下面是我的项目结构

demos/
src/
docs/
  source/
     config.py
     demos.rst
     modules.rst
     src.rst
     index.rst
     ....
  build/

以下是demos.rst的内容

Demonstration
=============

demos.tuto1
----------------------
demos/tuto1.ipynb

demos.tuto2
-------------------
demos/tuto2.ipynb

以下是index.rst的内容

Welcome to my python project
============================

.. toctree::
   :maxdepth: 2
   :caption: Contents:

   modules
   src
   demos


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

config.py文件中:

extensions = ['sphinx.ext.autodoc', 'sphinx.ext.autodoc', 'nbsphinx']
nbsphinx_execute = 'never'
nbsphinx_allow_errors = True
source_suffix = ['.rst', '.ipynb']
html_theme = 'sphinx_rtd_theme'

当我运行make html时,我渲染除jupyter笔记本之外的所有内容。 我错过了什么


Tags: 项目src文件夹refconfigdocssource内容
1条回答
网友
1楼 · 发布于 2024-04-29 13:14:55

您混淆了两个不同上下文之间的语法

如果您有一个toctree条目上下文,例如在index.rst中,则可以执行以下操作:

.. toctree::
    :maxdepth: 2
    :caption: Contents:

    modules
    src
    demos/tuto1.ipynb
    demos/tuto2.ipynb

如果希望有一个单独的"normal reST file",则可以执行以下操作:

.. _link: demos/tuto1.ipynb

相关问题 更多 >