gpt4 book ai didi

python - Sphinx Autodoc 无法正确导入

转载 作者:行者123 更新时间:2023-12-01 06:03:58 24 4
gpt4 key购买 nike

正如标题所示,我正在使用 Sphinx 为 python 库生成文档并使用自动文档功能。

我遇到的问题是 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 无法导入它。

最佳答案

这看起来像一个导入循环。尝试组织您的导入,以便它们不会在一个循环中相互依赖。

或者,您可以尝试重新排序。也许在 helpers.py 中将第 3 行移至文件底部,或类似的内容。

关于python - Sphinx Autodoc 无法正确导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8974115/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com