sphinx生成失败-autodoc无法导入/查找modu

2024-05-19 18:41:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我试着从狮身人面像开始,似乎有无情的问题。

命令:docs/sphinx-quickstart

我回答了所有的问题,一切都很好。

命令:docs/ls

一切看起来都很正常。结果:build Makefile source

命令: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!

我是斯芬克斯的新手,对这类文档还比较陌生。有人能提些建议吗?

编辑:

我希望能够使用Makefile来处理这个问题。到现在为止,我的项目中有两个文件夹。

nextgen/ls

docs ys_utils

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


Tags: noinimportbuildhomesphinxutilsrst
3条回答

conf.py

只需将路径添加到项目文件夹。

sys.path.append('/home/workspace/myproj/myproj')

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

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

顺便说一下:您可以使用Sphinx创建的Makefile来创建文档。 打个电话就行了

make

才能看到选择。

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

make clean

在运行make html之前。

听起来os.path.append()对人们来说工作正常,但是如果遵循conf.py模板,您可以使用os.path.insert(0, ...)将模块路径插入到sys.path前面,只需添加一个额外的.

import os
import sys
sys.path.insert(0, os.path.abspath('..'))

如果已将sphinx项目设置为使用单独的buildsource目录,则该调用应为:

sys.path.insert(0, os.path.abspath('../..'))

相关问题 更多 >