how to import module to sphinx

夙愿已清 提交于 2019-12-07 08:16:42

问题


import myModule as myModule

with this code works import and I can make my doc

import myPackage.myModule as myModule

with this I get "No module named myPackage.myModule" Doesnt matter if this file exist in root directory or in myPackage directory.

in RST-File I have not mentioned about myModule, I want to document other file that just import this module.


回答1:


Sphinx needs to be able to import your code, to generate documentation for classes and functions. You probably need to add your project's root folder to sys.path in Sphinx. You can do this from the Sphinx conf.py file:

import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

Replace '..' with the relative path to the project root.



来源:https://stackoverflow.com/questions/9002901/how-to-import-module-to-sphinx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!