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上创建了一个帐户,并进行了相应的设置(即 docs/
目录和 conf.py
文件).然后,基本上,我已经尝试了几乎所有方法: 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屋!