正如标题所说,我正在使用Sphinx为python库生成文档并使用自动doc函数。
我遇到的问题是autodoc导入器没有正确导入库。
Traceback (most recent call last):rs/user
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/decorators.py", line 4, in <module>
import response
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/response.py", line 2, in <module>
from lib.helpers import gtJSONEncoder
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/helpers.py", line 3, in <module>
from gt import Model, EMAIL_FROM, EMAIL_HOST
File "/Users/prggmr/Work/chevy/gt/software/gt/gt.py", line 114, in <module>
from modules.user import views
File "/Users/prggmr/Work/chevy/gt/software/gt/modules/user/views.py", line 5, in <module>
from lib import response
ImportError: cannot import name response
Traceback (most recent call last):json
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/helpers.py", line 2, in <module>
import response
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/response.py", line 2, in <module>
from lib.helpers import gtJSONEncoder
ImportError: cannot import name gtJSONEncoder
Traceback (most recent call last):messages
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
ImportError: No module named helper
Traceback (most recent call last):request
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/helpers.py", line 2, in <module>
import response
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/response.py", line 2, in <module>
from lib.helpers import gtJSONEncoder
ImportError: cannot import name gtJSONEncoder
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/helpers.py", line 2, in <module>
import response
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/response.py", line 2, in <module>
from lib.helpers import gtJSONEncoder
ImportError: cannot import name gtJSONEncoder
Traceback (most recent call last):ser
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/modules/user/models.py", line 6, in <module>
import gt
File "/Users/prggmr/Work/chevy/gt/software/gt/gt.py", line 114, in <module>
from modules.user import views
File "/Users/prggmr/Work/chevy/gt/software/gt/modules/user/views.py", line 7, in <module>
from lib.decorators import valid_user
File "/Users/prggmr/Work/chevy/gt/software/gt/lib/decorators.py", line 7, in <module>
from gt.modules.user.models import get_user_account, is_login_valid
ImportError: No module named modules.user.models
Traceback (most recent call last):ser
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/Users/prggmr/Work/chevy/gt/software/gt/modules/user/views.py", line 2, in <module>
from gt import app, TEMPLATES_PATH
File "/Users/prggmr/Work/chevy/gt/software/gt/gt.py", line 114, in <module>
from modules.user import views
ImportError: cannot import name views
我已经检查过路径是否正确,并且我将它们包含在系统路径中。
真正让我了解的是,我可以完美地运行应用程序,并且所有单元测试都通过了超过95%的代码覆盖率......但是sphinx无法导入它。
答案 0 :(得分:2)
这看起来像是一个导入循环。尝试组织您的导入,以便它们不会相互依赖。
或者,您可以尝试重新排序它们。也许在helpers.py
移动第3行到文件的底部,或类似的东西。