python的sphinx autodoc没有显示任何内容(在readthedocs上) [英] sphinx autodoc for python doesn't show anything (on readthedocs)
问题描述
我有 这个 python 包,我想使用 Sphinx 自动记录它.我已经在每个函数和类中插入了文档字符串.
I have this python package that I'd like to automatically document using Sphinx. I've inserted docstrings in every functions and classes.
我在 ReadTheDocs 上注册了一个帐户,并进行了相应的设置(即,一个带有 conf.py
文件的 docs/
目录).然后,基本上,我几乎尝试了所有方法:autodoc::
、autofunction::
、autoclass::
的每种组合;我尝试使用 same conf.py
文件作为其他记录 API 的包(当然,根据我的情况进行了特定的更改);但它不起作用,API 页面仍然空无一人...
I made an account on ReadTheDocs, and did the setup accordingly (i.e., a docs/
dir with a conf.py
file). Then, basically, I've tried almost everything: every combination of autodoc::
, autofunction::
, autoclass::
; I tried using the same conf.py
file as other packages which documented API (with specific changes made according to my case, of course); but it just doesn't work, the API page remains inexorably empty...
推荐答案
尝试将其添加到您的 conf.py 中:
Try to add this to your conf.py :
########### TRICK FOUND ON SOME TUTORIAL : ADD IN THE MOCK_MODULES ANY EXTERNAL MODULE YOU'RE USING IN YOUR PACKAGE.
import mock
MOCK_MODULES = ['numpy', 'scipy', 'sklearn', 'matplotlib', 'matplotlib.pyplot', 'scipy.interpolate', 'scipy.special', 'math', '__future__', 'toolboxutilities']
for mod_name in MOCK_MODULES:
sys.modules[mod_name] = mock.Mock()
在 MOCK_MODULES 中,添加您的项目使用的任何单个外部导入.我遇到了完全相同的问题,这解决了它.
In the MOCK_MODULES, add any single external import that your project uses. I had exactly the same problem and this solved it.
也在 conf.py 中,不要忘记添加:
Also in the conf.py, don't forget to add the :
sys.path.insert(0, os.path.abspath('../..'))
在您的情况下,您已经拥有它,但我会提到它,以防其他有同样问题的人看到我的答案.
In your case you already have it but I mention it in case someone else with the same problem would see my answer.
这篇关于python的sphinx autodoc没有显示任何内容(在readthedocs上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!