python - sphinx-build 失败 - autodoc 无法导入/查找模块

标签 python python-sphinx autodoc

我正在尝试开始使用 Sphinx,但似乎遇到了很多问题。

命令:docs/sphinx-quickstart

我回答了所有问题,一切正常。

命令:docs/ls

一切看起来都很正常。结果:构建 Makefile 源代码

命令:sphinx-build -d build/doctrees source build/html

它似乎工作。我能够打开 index.html 文件并看到我想要的“外壳”。

当我尝试将我的实际源代码作为 source 文件夹时,我遇到了问题。

命令:sphinx-build -d build/doctrees ../ys_utils build/html

结果:

Making output directory...
Running Sphinx v1.1.3
loading pickled environment... not yet created
No builder selected, using default: html
loading intersphinx inventory from http://docs.python.org/objects.inv...
building [html]: targets for 1 source files that are out of date
updating environment: 1 added, 0 changed, 0 removed
Traceback (most recent call last):                                                                                               
  File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.1.3-py2.6.egg/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
ImportError: No module named ys_utils
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.1.3-py2.6.egg/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
ImportError: No module named ys_utils.test_validate_ut
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.1.3-py2.6.egg/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
ImportError: No module named ys_utils.git_utils
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.1.3-py2.6.egg/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
ImportError: No module named setup.setup

/home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:4: WARNING: autodoc can't import/find module 'ys_utils', it reported error: "No module named ys_utils", please check your spelling and sys.path
/home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:10: WARNING: autodoc can't import/find module 'ys_utils.test_validate_ut', it reported error: "No module named ys_utils.test_validate_ut", please check your spelling and sys.path
/home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:12: WARNING: don't know which module to import for autodocumenting u'UnitTests' (try placing a "module" or "currentmodule" directive in the document, or giving an explicit module name)
/home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:18: WARNING: autodoc can't import/find module 'ys_utils.git_utils', it reported error: "No module named ys_utils.git_utils", please check your spelling and sys.path
/home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:24: WARNING: autodoc can't import/find module 'setup.setup', it reported error: "No module named setup.setup", please check your spelling and sys.path
WARNING: master file /home/ricomoss/workspace/nextgen/ys_utils/index.rst not found
looking for now-outdated files... none found
pickling environment... done
checking consistency... /home/ricomoss/workspace/nextgen/ys_utils/ys_utils.rst:: WARNING: document isn't included in any toctree
done
preparing documents... done
writing output... [ 50%] index                                                                                                   
Exception occurred:
  File "/usr/local/lib/python2.6/dist-packages/Sphinx-1.1.3-py2.6.egg/sphinx/environment.py", line 1213, in get_doctree
    f = open(doctree_filename, 'rb')
IOError: [Errno 2] No such file or directory: '/home/ricomoss/workspace/nextgen/docs/build/doctrees/index.doctree'
The full traceback has been saved in /tmp/sphinx-err-jjJ7gM.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
Either send bugs to the mailing list at <http://groups.google.com/group/sphinx-dev/>,
or report them in the tracker at <http://bitbucket.org/birkenfeld/sphinx/issues/>. Thanks!

我是 Sphinx 的新手,对这类文档也比较陌生。谁能给点建议?

编辑:

我希望能够使用 Makefile 来处理这个问题。截至目前,我的项目中有两个文件夹。

nextgen/ls

docs ys_utils

我需要 nextgen/docs/Makefileys_utils 和我将拥有的所有其他模块生成 HTML。

最佳答案

Autodoc 找不到您的模块,因为它们不在 sys.path 中。

您必须在 conf.pysys.path 中包含模块的路径。 查看你的 conf.py 的顶部(就在 sys 的导入之后),有一个 sys.path.insert() 语句,你可以适应。

顺便说一句:您可以使用 Sphinx 创建的 Makefile 来创建文档。 只需调用电话

make

查看选项。

如果在尝试之前出现问题:

make clean

在运行 make html 之前。

关于python - sphinx-build 失败 - autodoc 无法导入/查找模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10324393/

相关文章:

python-sphinx - 如何在单词之间添加额外的水平空白

python - 属性错误: 'Values' object has no attribute 'tab_width' when running sphinx-build

Python:Sphinx namedtuple 文档

python - 如何结合 sphinx 文档字符串在 numpy 文档字符串中正确添加嵌套列表

python - Django:通过相关模型字段从查询集中删除重复项(分组依据)

python - 新的数据框列在一行中查找值并从另一列返回值

python - 如何将本地目录包含到 Sphinx 文档中?

python - 使用 scipy 最大化目标(通过 kelly criterium)

python - 未绑定(bind)本地错误 : Decorator with default parameters