Failed to import module when building the sphinx documentation

会有一股神秘感。 提交于 2019-12-24 09:38:30

问题


I'm using Sphinx version 1.4.5.

My project structure is the following:

+ src > main.py + docs (generated with sphinx-quickstart)

Even after adding the path to the src folder in docs/conf.py:

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

And generating the rst file for src/main.py (i.e. docs/src.rst and docs/modules.rst) with:

$ sphinx-apidoc -fo docs src

When I try to build the html webpages with:

$ make clean
$ make html

It couldn't find both the src module and src/main.py:

WARNING: autodoc: failed to import module u'src.main'; the following exception was raised


回答1:


Try doing this for your path insertion instead:

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

Also consider a better name for your directory than src.




回答2:


Your current working directory should be the directory of your makefile, which should be docs.



来源:https://stackoverflow.com/questions/38963631/failed-to-import-module-when-building-the-sphinx-documentation

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