Sphinx Autodoc导入不正确

2024-10-01 00:21:27 发布

您现在位置:Python中文网/ 问答频道 /正文

正如标题所说,我使用Sphinx为python库生成文档,并使用auto 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%以上的代码覆盖率。。。但是斯芬克斯不能进口它。在


Tags: infrompyimportgtliblinesoftware
1条回答
网友
1楼 · 发布于 2024-10-01 00:21:27

这看起来像是一个导入循环。尽量组织好你的进口商品,这样他们就不会在一个圈子里互相依赖了。在

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

相关问题 更多 >