首页 > 解决方案 > Sphinx autodoc 无法导入模块

问题描述

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

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

当我尝试运行make html时,libsmop并且recipes导入时没有任何问题,但是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 > ...}

标签: pythonpython-sphinxautodoc

解决方案


由于您的 autodoc 正在获取一些模块,因此可能是因为失败模块的依赖项要么是 1)未正确导入,要么是 2)未安装在您的 python 环境下。您将需要检查所有导入语句是否在失败的模块中工作。


推荐阅读