gpt4 book ai didi

django - 狮身人面像 : Autodoc ImportError

转载 作者:行者123 更新时间:2023-12-02 09:54:56 24 4
gpt4 key购买 nike

我正在尝试自动生成我的 Django 项目的文档。文档树在 html 页面上生成,但我的任何模块中的任何成员都没有文档。我一直遇到这个问题:

Running Sphinx v1.1.3
loading pickled environment... not yet created
building [html]: targets for 2 source files that are out of date
updating environment: 2 added, 0 changed, 0 removed
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/admin.py", line 1, in <module>
from tool.models import All_alerts
File "/home/tim/Desktop/fqdn/mysite/tool/models.py", line 3, in <module>
from django.db import models
ImportError: No module named django.db
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/forms.py", line 1, in <module>
from django import forms
ImportError: No module named django
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/models.py", line 3, in <module>
from django.db import models
ImportError: No module named django.db
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/page1urls.py", line 1, in <module>
from django.conf.urls import patterns, url, include
ImportError: No module named django.conf.urls
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/page2urls.py", line 1, in <module>
from django.conf.urls import patterns, url, include
ImportError: No module named django.conf.urls
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/page3urls.py", line 1, in <module>
from django.conf.urls import patterns, url, include
ImportError: No module named django.conf.urls
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/page4urls.py", line 1, in <module>
from django.conf.urls import patterns, url, include
ImportError: No module named django.conf.urls
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/tests.py", line 1, in <module>
from django.test import TestCase
ImportError: No module named django.test
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/urls.py", line 1, in <module>
from django.conf.urls import patterns, url, include
ImportError: No module named django.conf.urls
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 321, in import_object
__import__(self.modname)
File "/home/tim/Desktop/fqdn/mysite/tool/views.py", line 1, in <module>
from tool.models import Product
File "/home/tim/Desktop/fqdn/mysite/tool/models.py", line 3, in <module>
from django.db import models
ImportError: No module named django.db

/home/tim/Desktop/fqdn/mysite/docs/tool.rst:7: WARNING: autodoc can't import/find module 'tool.admin', it reported error: "No module named django.db", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:15: WARNING: autodoc can't import/find module 'tool.forms', it reported error: "No module named django", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:23: WARNING: autodoc can't import/find module 'tool.models', it reported error: "No module named django.db", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:31: WARNING: autodoc can't import/find module 'tool.page1urls', it reported error: "No module named django.conf.urls", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:39: WARNING: autodoc can't import/find module 'tool.page2urls', it reported error: "No module named django.conf.urls", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:47: WARNING: autodoc can't import/find module 'tool.page3urls', it reported error: "No module named django.conf.urls", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:55: WARNING: autodoc can't import/find module 'tool.page4urls', it reported error: "No module named django.conf.urls", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:63: WARNING: autodoc can't import/find module 'tool.tests', it reported error: "No module named django.test", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:71: WARNING: autodoc can't import/find module 'tool.urls', it reported error: "No module named django.conf.urls", please check your spelling and sys.path
/home/tim/Desktop/fqdn/mysite/docs/tool.rst:79: WARNING: autodoc can't import/find module 'tool.views', it reported error: "No module named django.db", please check your spelling and sys.path

我一直在网上寻找任何解决方案。我尝试重新排列模块内的导入语句,但没有任何效果。

sys.path.insert(0, os.path.abspath('/home/tim/Desktop/fqdn/mysite/tool/'))

我的所有模块都在工具文件夹中。迫切需要任何帮助。谢谢!

另外,automodule不是封装了autofunction吗?那么我们为什么要使用自动函数呢?

最佳答案

您应该使用MagicMock简化依赖关系。

在你的conf.py中:

from unittest.mock import MagicMock
import sys

MODULES = ['django']
for mod_name in MODULES:
sys.modules[mod_name] = MagicMock()

关于django - 狮身人面像 : Autodoc ImportError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25558472/

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