python - Sphinx autodoc 无法导入模块

标签 python python-sphinx autodoc

我正在尝试使用 Sphinx 记录一个项目,但遇到了一个问题,即仅从文件夹中导入了一些模块。我的项目结构如下所示:

Project
|
|--Main
|    |--Scripts
|          __init__.py
|          libsmop.py
|          conv_table.py
|          f_discrim.py
|          recipes.py
|          ...

当我尝试运行时 make html , libsmoprecipes导入没有任何问题,但是 conv_tablef_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/

相关文章:

python - 更改 Pandas 数据框特定列的数据类型

python - Sphinx LaTeX 标记限制

python-sphinx - 使用 Read The Docs & Sphinx 和 ReadTheDocs 主题时删除在 Github 上的编辑链接

python-sphinx - Sphinx Autodoc 输出顺序

python - 为什么 python/pil 不将填充 FF 的二维数组保存为全白 bmp 图像?

python - 在 Python 中获取窗口标题 - 困难的方法?

python - 带有 Sphinx 的“意外章节标题”——是 numpy 问题吗?

python - Sphinx 不显示泛型类的类实例化参数(即参数类型)

python - Sphinx Autodoc 删除空的子模块和包

python - 在 Gensim 中通过 ID 检索文档的字符串版本