狮身人面像建造失败 - 车博士无法导入/查找模块(sphinx-build fail - autod

2019-06-23 23:54发布

我想开始使用狮身人面像,似乎有无情的问题。

命令: 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/Makefile生成的HTML ys_utils和所有其他的模块,我将不得不。

Answer 1:

车博士找不到你的模块,因为它们不是在sys.path

你必须包括在路径到模块sys.pathconf.py 。 看看你的顶部conf.py (只是进口后sys ),有一个sys.path.insert()语句,它可以适应。

顺便说一句:你可以使用Makefile的狮身人面像创建来创建文档。 只需致电

make

查看选项。

如果出了问题再进行尝试:

make clean

之前运行make html



Answer 2:

conf.py

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

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


Answer 3:

这听起来像os.path.append()正在确定为乡亲,但如果按照conf.py模板,需要插入模块路径的前sys.path使用os.path.insert(0, ...) ,只是添加一个额外的.

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

如果您已经安装您的sphinx的项目使用单独的buildsource目录,该呼叫应改为:

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


Answer 4:

我想,我这做了我第一次尝试将文件添加到toctree。 我想这是因为我离开了之间的空白行:MAXDEPTH线和文件名。

.. Animatrix Concepts documentation master file, created by
   sphinx-quickstart on Thu Mar 22 18:06:15 2012.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Welcome to Animatrix Concepts documentation!
============================================

Contents:

.. toctree::
   :maxdepth: 2

   stuff


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

以上是我的index.rst文件。 stuff.rst驻留在同一目录中它。



Answer 5:

您可以使用Pweave和noweb格式生成RST文件,其中包括在其中嵌入代码的输出。 基本上,你写你的第一个文件,嵌入在显着大块类似这样的Python代码:

<<echo=False>>=
print("some text that will appear in the rst file")
@

和Pweave将执行这些块,并与他们的第一个产生文件输出,你可以再与狮身人面像使用替换它们。 见Pweave REST示例为它的外观的更多细节。



Answer 6:

狮身人面像并不是很python3兼容,运行__import__(module_name) importlib.import_module(module_name)在我的翻译都工作,但不是在狮身人面像。

我尝试检查出狮身人面像的主分支,改变了我的解释,以python3.4在Makefile ,并在3.x系列中删除的模块有错误。 你可以在这里看到我的问题的报告:

https://github.com/sphinx-doc/sphinx/issues/2046



文章来源: sphinx-build fail - autodoc can't import/find module