繁体   English   中英

如何在 sphinx 中包含模块

[英]how include module in sphinx

一个星期以来,我一直在寻找这个问题的答案。 希望你能帮我:

我正在使用 Sphinx 进行记录,这是我的项目结构:

-folder
    __init__
    -main_tool_folder
        __init__
        main.py
        -docs_folder
    -modulefolder
        __init__
        fileIwanttodocument     

在我的 main.py 里面

sys.path.append('../')
from modulefolder.fileIwanttodocument import functionIneed

并且代码有效

当涉及到 Sphinx 时,它失败了(在我执行导入的行中出错)

在我的 conf.py 我使用

sys.path.insert(0, os.path.abspath('../'))
sys.path.insert(1, os.path.abspath('../../'))

并在 code.rst

.. automodule:: main
   :members

.. automodule:: modulefolder.fileIwanttodocument
   :members:

如何包含 fileIwanttodocument.py ? 到目前为止我发现的唯一方法是将它复制到 main_tool_folder 中,这违背了创建模块的目的

自己解决了! 在 conf.py 之前

sys.path.insert(0, os.path.abspath('../'))
sys.path.insert(1, os.path.abspath('../../'))

我有

sys.path.insert(0, os.path.dirname(os.getcwd()))

这引起了问题。

显然我的做法是正确的!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM