我正在使用Sphinx为我正在处理的项目自动构建文档。文档构建正常,直到我向其中一个模块添加了另一个类。现在每当我尝试运行构建时,都不会导入新类。
Sphinx错误日志中的错误:
# Sphinx version: 1.2b3
# Python version: 2.7.3
# Docutils version: 0.9 release
# Jinja2 version: 2.6
# Loaded extensions:
# sphinxcontrib.httpdomain from C:\Python27\lib\site-packages\sphinxcontrib_httpdomain-1.2.1-py2.7.egg\sphinxcontrib\httpdomain.pyc
# sphinxcontrib.autohttp.flask from C:\Python27\lib\site-packages\sphinxcontrib_httpdomain-1.2.1-py2.7.egg\sphinxcontrib\autohttp\flask.pyc
# sphinx.ext.autodoc from C:\Python27\lib\site-packages\sphinx\ext\autodoc.pyc
# sphinx.ext.viewcode from C:\Python27\lib\site-packages\sphinx\ext\viewcode.pyc
# sphinx.ext.oldcmarkup from C:\Python27\lib\site-packages\sphinx\ext\oldcmarkup.pyc
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\sphinx\cmdline.py", line 246, in main
app.build(force_all, filenames)
File "C:\Python27\lib\site-packages\sphinx\application.py", line 212, in build
self.builder.build_update()
File "C:\Python27\lib\site-packages\sphinx\builders\__init__.py", line 214, in build_update
'out of date' % len(to_build))
File "C:\Python27\lib\site-packages\sphinx\builders\__init__.py", line 234, in build
purple, length):
File "C:\Python27\lib\site-packages\sphinx\builders\__init__.py", line 134, in status_iterator
for item in iterable:
File "C:\Python27\lib\site-packages\sphinx\environment.py", line 470, in update_generator
self.read_doc(docname, app=app)
File "C:\Python27\lib\site-packages\sphinx\environment.py", line 618, in read_doc
pub.publish()
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\core.py", line 221, in publish
self.settings)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\readers\__init__.py", line 69, in read
self.parse()
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\readers\__init__.py", line 75, in parse
self.parser.parse(self.input, document)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\__init__.py", line 162, in parse
self.statemachine.run(inputlines, document, inliner=self.inliner)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 174, in run
input_source=document['source'])
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\statemachine.py", line 239, in run
context, state, transitions)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\statemachine.py", line 460, in check_line
return method(match, context, next_state)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 2706, in underline
self.section(title, source, style, lineno - 1, messages)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 331, in section
self.new_subsection(title, lineno, messages)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 399, in new_subsection
node=section_node, match_titles=True)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 286, in nested_parse
node=node, match_titles=match_titles)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 199, in run
results = StateMachineWS.run(self, input_lines, input_offset)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\statemachine.py", line 239, in run
context, state, transitions)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\statemachine.py", line 460, in check_line
return method(match, context, next_state)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 2706, in underline
self.section(title, source, style, lineno - 1, messages)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 331, in section
self.new_subsection(title, lineno, messages)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 399, in new_subsection
node=section_node, match_titles=True)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 286, in nested_parse
node=node, match_titles=match_titles)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 199, in run
results = StateMachineWS.run(self, input_lines, input_offset)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\statemachine.py", line 239, in run
context, state, transitions)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\statemachine.py", line 460, in check_line
return method(match, context, next_state)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 2279, in explicit_markup
nodelist, blank_finish = self.explicit_construct(match)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 2291, in explicit_construct
return method(self, expmatch)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 2034, in directive
directive_class, match, type_name, option_presets)
File "C:\Python27\lib\site-packages\docutils-0.9-py2.7.egg\docutils\parsers\rst\states.py", line 2083, in run_directive
result = directive_instance.run()
File "C:\Python27\lib\site-packages\sphinxcontrib_httpdomain-1.2.1-py2.7.egg\sphinxcontrib\autohttp\flask.py", line 138, in run
for line in self.make_rst():
File "C:\Python27\lib\site-packages\sphinxcontrib_httpdomain-1.2.1-py2.7.egg\sphinxcontrib\autohttp\flask.py", line 97, in make_rst
app = import_object(self.arguments[0])
File "C:\Python27\lib\site-packages\sphinxcontrib_httpdomain-1.2.1-py2.7.egg\sphinxcontrib\autohttp\common.py", line 17, in import_object
mod = __import__(module_name)
File "E:\workspace_zach\API\api_serve.py", line 6, in <module>
from BOBI import BOBI
File "E:\workspace_zach\API\BOBI\__init__.py", line 13, in <module>
from Lib.DBVersionTools import DBVersionNormalizer, DBVersionPolisher
ImportError: cannot import name DBVersionPolisher
模块位于路径上,位于包含__init__.py
文件的文件夹中。 Sphinx显然能够导入第一类,但不能导入第二类。涉及两个类的测试工作正常。我删除了所有旧的.pyc文件,但未能解决问题。如果我从import语句中删除第二个类并注释掉对它的引用,那么文档的工作没有问题。
有关如何解决此问题的任何想法,或者未能隐藏sphinx的导入语句(但不是其他脚本,例如我的测试)?
附加代码:
所有导入声明:
import Error
import logging
import re
import Lib.globals as Globals
from flask import Blueprint, jsonify, request, current_app, make_response
from functools import update_wrapper
from datetime import timedelta
from Lib.VerifyCookie import verify, req_to_dict
from Lib.MSSQLTools import MSSQLTools
from Lib.DBVersionTools import DBVersionNormalizer, DBVersionPolisher
Sphinx扩展和路径修改:
sys.path.append('E:\\workspace_zach\\API') # Root directory for the project
extensions = [
'sphinx.ext.autodoc',
'sphinxcontrib.httpdomain',
'sphinxcontrib.autohttp.flask',
'sphinx.ext.autodoc',
'sphinx.ext.viewcode',
]
答案 0 :(得分:0)
该文件的先前版本没有导入修改,存在于我正在开发的计算机的另一个路径上,并已添加到pythonpath中。
sys.path.remove('E:\\workspace\\API')
足以删除其他路径并解决问题。