我正在尝试使用 Sphinx 记录一个项目,但遇到了一个问题,即仅从文件夹中导入了一些模块。我的项目结构如下所示:
Project
|
|--Main
| |--Scripts
| __init__.py
| libsmop.py
| conv_table.py
| f_discrim.py
| recipes.py
| ...
当我尝试运行时
make html
, libsmop
和 recipes
导入没有任何问题,但是 conv_table
和 f_discrim
得到以下错误:WARNING: autodoc: failed to import module u'conv_table' from module u'Scripts'; the following exception was raised:No module named conv_table
我不认为这是我的配置文件,因为当我运行时它会找到所有文件
sphinx-apidoc -o _rst Main/Scripts
我已经确认它们出现在结果 Scripts.rst
中文件。为什么 autodoc 会找到一些模块而不是其他模块?
编辑:
conv_table.py
是这种形式:import re
import numpy as np
"""
conv_table dictionary at the bottom of this file maps from matlab functions
to their python equivalents.
"""
def get_args(line,separator=",", open_char='(', close_char=')'):
"""Returns the arguments of line
>>> get_args('ones(3,1,length(arr))')
...
< a bunch of function definitions>
...
conv_table = {... < a very big dictionary > ...}
最佳答案
由于您的 autodoc 正在获取一些模块,这可能是因为失败模块的依赖项 1) 未正确导入或 2) 未安装在您的 python 环境下。您将需要检查所有导入语句是否在您失败的模块中工作。
关于python - Sphinx autodoc 无法导入模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54815714/