Sphinx 找不到特定目录中的模块

发布于 2025-01-12 21:00:34 字数 1217 浏览 3 评论 0原文

我在 Python 中遇到了 Sphinx 的问题。即使我已按照 https://groups.google 的说明进行操作。 com/forum/#!topic/sphinx-users/lO4CeNJQWjg 我无法解决它。

我有 Docs/source 文件夹,其中包含:

  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 时,出现 2 个主要错误:

D:\hfTools\Projects\Validation-Source\Docs\source\RstFiles\BatchDataContainer.rst: 警告:文档不包含在任何目录树中

并且

警告:autodoc:无法从以下位置导入模块“BatchDataContainer” 模块“RstFiles”;引发以下异常:没有名为的模块 “第一个文件”

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

I have faced a problem with Sphinx in Python. Even if I have followed the instructions from https://groups.google.com/forum/#!topic/sphinx-users/lO4CeNJQWjg I was not able to solve it.

I have Docs/source folder which contains:

  1. conf.py
  2. index.rst
  3. RstFiles (the folder which contains .rst files for each module).

In conf.py I specify the abs path in the following way:
sys.path.insert(0, os.path.abspath('..'))

In index.rst I call all the modules from RstFiles folder in the following way:

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

   BatchDataContainer.rst
   BatchDefaultValues.rst
   BatchTypes.rst

And finally, the content of each .rst file is in the following way:

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

When I run sphinx-build I get 2 main errors:

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

and

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

Any ideas what might be wrong cause I have tried different things already and nothing has helped?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧伤慢歌 2025-01-19 21:00:34

如果conf.py位于此目录中,则

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

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

D: \hfTools\Projects\Validation-Source\Products

那么你需要 sys.path.insert(0, os.path.abspath('../..')) 在conf.py。

automodule 指令也需要更新:

.. automodule:: Products.BatchDataContainer
   :members:

If conf.py is located in this directory,

D:\hfTools\Projects\Validation-Source\Docs\source,

and the project's Python modules (including BatchDataContainer.py) are in

D:\hfTools\Projects\Validation-Source\Products,

then you need sys.path.insert(0, os.path.abspath('../..')) in conf.py.

The automodule directive needs to be updated as well:

.. automodule:: Products.BatchDataContainer
   :members:
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文