简体   繁体   English

如何在 sphinx 中包含模块

[英]how include module in sphinx

I have been looking for an answer to this issue for a week.一个星期以来,我一直在寻找这个问题的答案。 Hope you can help me:希望你能帮我:

I am documenting with Sphinx and this is the structure of my project:我正在使用 Sphinx 进行记录,这是我的项目结构:

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

Inside my main.py在我的 main.py 里面

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

and the code works并且代码有效

When it comes to Sphinx it fails (gives error on the line where I do the import)当涉及到 Sphinx 时,它失败了(在我执行导入的行中出错)

In my conf.py I use在我的 conf.py 我使用

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

and in code.rst并在 code.rst

.. automodule:: main
   :members

.. automodule:: modulefolder.fileIwanttodocument
   :members:

How can I include fileIwanttodocument.py ?如何包含 fileIwanttodocument.py ? The only way I've found so far is to copy it inside main_tool_folder and this defeats the purpose of creating modules到目前为止我发现的唯一方法是将它复制到 main_tool_folder 中,这违背了创建模块的目的

Solved it myself!自己解决了! in conf.py before在 conf.py 之前

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

I had我有

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

that was causing issues.这引起了问题。

apparently the way I am doing is correct!显然我的做法是正确的!

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

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