我正在使用 Sphinx 为 python 项目生成文档。我有大约 6 个不同的包裹;其中 5 个工作正常,但每当我尝试为第 6 个生成文档时,我都会收到以下错误消息:
Exception occurred:
File "/usr/local/lib/python3.3/site-packages/sphinx/ext/autodoc.py", line 1066, in can_document_member
return isinstance(member, class_types) and \
NameError: Unknown C global variable
狮身人面像错误日志:
# Sphinx version: 1.1.3
# Python version: 3.3.2
# Docutils version: 0.11 release
# Jinja2 version: 2.7.1
Traceback (most recent call last):
File "/usr/local/lib/python3.3/site-packages/sphinx/cmdline.py", line 189, in main
app.build(force_all, filenames)
File "/usr/local/lib/python3.3/site-packages/sphinx/application.py", line 204, in build
self.builder.build_update()
File "/usr/local/lib/python3.3/site-packages/sphinx/builders/__init__.py", line 196, in build_update
'out of date' % len(to_build))
File "/usr/local/lib/python3.3/site-packages/sphinx/builders/__init__.py", line 216, in build
purple, length):
File "/usr/local/lib/python3.3/site-packages/sphinx/builders/__init__.py", line 120, in status_iterator
for item in iterable:
File "/usr/local/lib/python3.3/site-packages/sphinx/environment.py", line 613, in update_generator
self.read_doc(docname, app=app)
File "/usr/local/lib/python3.3/site-packages/sphinx/environment.py", line 761, in read_doc
pub.publish()
File "/usr/local/lib/python3.3/site-packages/docutils/core.py", line 217, in publish
self.settings)
File "/usr/local/lib/python3.3/site-packages/docutils/readers/__init__.py", line 72, in read
self.parse()
File "/usr/local/lib/python3.3/site-packages/docutils/readers/__init__.py", line 78, in parse
self.parser.parse(self.input, document)
File "/usr/local/lib/python3.3/site-packages/docutils/parsers/rst/__init__.py", line 172, in parse
self.statemachine.run(inputlines, document, inliner=self.inliner)
File "/usr/local/lib/python3.3/site-packages/docutils/parsers/rst/states.py", line 170, in run
input_source=document['source'])
File "/usr/local/lib/python3.3/site-packages/docutils/statemachine.py", line 239, in run
context, state, transitions)
File "/usr/local/lib/python3.3/site-packages/docutils/statemachine.py", line 460, in check_line
return method(match, context, next_state)
File "/usr/local/lib/python3.3/site-packages/docutils/parsers/rst/states.py", line 2726, in underline
self.section(title, source, style, lineno - 1, messages)
File "/usr/local/lib/python3.3/site-packages/docutils/parsers/rst/states.py", line 327, in section
self.new_subsection(title, lineno, messages)
File "/usr/local/lib/python3.3/site-packages/docutils/parsers/rst/states.py", line 395, in new_subsection
node=section_node, match_titles=True)
File "/usr/local/lib/python3.3/site-packages/docutils/parsers/rst/states.py", line 282, in nested_parse
node=node, match_titles=match_titles)
File "/usr/local/lib/python3.3/site-packages/docutils/parsers/rst/states.py", line 195, in run
results = StateMachineWS.run(self, input_lines, input_offset)
File "/usr/local/lib/python3.3/site-packages/docutils/statemachine.py", line 239, in run
context, state, transitions)
File "/usr/local/lib/python3.3/site-packages/docutils/statemachine.py", line 460, in check_line
return method(match, context, next_state)
File "/usr/local/lib/python3.3/site-packages/docutils/parsers/rst/states.py", line 2726, in underline
self.section(title, source, style, lineno - 1, messages)
File "/usr/local/lib/python3.3/site-packages/docutils/parsers/rst/states.py", line 327, in section
self.new_subsection(title, lineno, messages)
File "/usr/local/lib/python3.3/site-packages/docutils/parsers/rst/states.py", line 395, in new_subsection
node=section_node, match_titles=True)
File "/usr/local/lib/python3.3/site-packages/docutils/parsers/rst/states.py", line 282, in nested_parse
node=node, match_titles=match_titles)
File "/usr/local/lib/python3.3/site-packages/docutils/parsers/rst/states.py", line 195, in run
results = StateMachineWS.run(self, input_lines, input_offset)
File "/usr/local/lib/python3.3/site-packages/docutils/statemachine.py", line 239, in run
context, state, transitions)
File "/usr/local/lib/python3.3/site-packages/docutils/statemachine.py", line 460, in check_line
return method(match, context, next_state)
File "/usr/local/lib/python3.3/site-packages/docutils/parsers/rst/states.py", line 2299, in explicit_markup
nodelist, blank_finish = self.explicit_construct(match)
File "/usr/local/lib/python3.3/site-packages/docutils/parsers/rst/states.py", line 2311, in explicit_construct
return method(self, expmatch)
File "/usr/local/lib/python3.3/site-packages/docutils/parsers/rst/states.py", line 2054, in directive
directive_class, match, type_name, option_presets)
File "/usr/local/lib/python3.3/site-packages/docutils/parsers/rst/states.py", line 2103, in run_directive
result = directive_instance.run()
File "/usr/local/lib/python3.3/site-packages/sphinx/ext/autodoc.py", line 1303, in run
documenter.generate(more_content=self.content)
File "/usr/local/lib/python3.3/site-packages/sphinx/ext/autodoc.py", line 734, in generate
self.document_members(all_members)
File "/usr/local/lib/python3.3/site-packages/sphinx/ext/autodoc.py", line 629, in document_members
classes = [cls for cls in AutoDirective._registry.values()
File "/usr/local/lib/python3.3/site-packages/sphinx/ext/autodoc.py", line 630, in <listcomp>
if cls.can_document_member(member, mname, isattr, self)]
File "/usr/local/lib/python3.3/site-packages/sphinx/ext/autodoc.py", line 1066, in can_document_member
return isinstance(member, class_types) and \
NameError: Unknown C global variable
我看不出一个有问题的包和那些正常工作的包之间有任何明显的区别,而且 Sphinx 错误似乎没有指向我的东西的任何特定问题部分。有谁知道这可能是什么原因?
下面的UPDATE mzjn 似乎击中了它,但错误有点令人费解。我使用的是 SWIG,出于某种原因,来自其他模块的通配符导入语句,即
from foo import *
当 foo 从 SWIG 生成的模块导入某些内容时,导致 Sphinx 崩溃。但是,如果我通过并替换为特定的导入语句
from foo import bar
其中 bar 是我真正需要的 foo 类,然后一切正常。