Sphinx没有从特定目录中找到模块

2024-09-30 18:24:55 发布

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

我在Python中遇到了Sphinx的问题。即使我遵循了https://groups.google.com/forum/#!topic/sphinx-users/lO4CeNJQWjg的指示,我也无法解决它

我有文档/源文件夹,其中包含:

  1. conf.py
  2. index.rst
  3. RstFiles(包含每个模块的.rst文件的文件夹)

在conf.py中,我用以下方式指定abs路径: sys.path.insert(0, os.path.abspath('..'))

在index.rst中,我通过以下方式调用RstFiles文件夹中的所有模块:

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

   BatchDataContainer.rst
   BatchDefaultValues.rst
   BatchTypes.rst

最后,每个.rst文件的内容如下所示:

BatchDataContainer 
==================
.. automodule:: RstFiles.BatchDataContainer
   :members:

当我运行sphinx build时,我得到两个主要错误:

D:\hfTools\Projects\Validation-Source\Docs\source\RstFiles\BatchDataContainer.rst: WARNING: document isn't included in any toctree

WARNING: autodoc: failed to import module 'BatchDataContainer' from module 'RstFiles'; the following exception was raised: No module named 'RstFiles'

有什么想法可能是错误的,因为我已经尝试了不同的东西,但没有任何帮助


Tags: 模块文件pathpy文件夹indexconf错误
1条回答
网友
1楼 · 发布于 2024-09-30 18:24:55

如果conf.py位于该目录中

D:\hfTools\Projects\Validation Source\Docs\Source

该项目的Python模块(包括BatchDataContainer.py)位于

D:\hfTools\Projects\Validation Source\Products

然后您需要conf.py中的sys.path.insert(0, os.path.abspath('../..'))

automodule指令也需要更新:

.. automodule:: Products.BatchDataContainer
   :members:

相关问题 更多 >