【问题标题】:Sphinx-api cannot import modules of Django projectSphinx-api 无法导入 Django 项目的模块
【发布时间】:2012-01-15 03:16:03
【问题描述】:

我已经在我的 virtualenv 中,我确信一切都在 python 路径上。

(myenv)admin@ubuntu:/var/lib/mydirectory/doc$ sphinx-apidoc -o . ../testproject/

Creating file ./testproject.rst.
Creating file ./testproject.apps.rst.
# ... and many more .... #
Creating file ./modules.rst.

(myenv)admin@ubuntu:/var/lib/mydirectory/doc$ make html
sphinx-build -b html -d _build/doctrees   . _build/html
Making output directory...
Running Sphinx v1.1.2
loading pickled environment... not yet created
building [html]: targets for 17 source files that are out of date
updating environment: 17 added, 0 changed, 0 removed

Traceback (most recent call last):t                                                                                  
  File "/var/lib/server/myenv/lib/python2.6/site-packages/sphinx/ext/autodoc.py", line 321, in import_object
    __import__(self.modname)
ImportError: No module named webclient.__init__
# ... and many more .... #

/var/lib/mydirectory/doc/testproject.rst:7: WARNING: autodoc can't import/find module 'testproject.__init__', it reported error: "No module named testproject.__init__", please check your spelling and sys.path
# ... and many more .... #

当我打开 html 文件时,我只看到标题和章节标题。没有自动文档。

是什么导致了这个问题?我已经在我的虚拟环境中...

有什么想法吗?我正在使用 Sphinx 1.1.2。

谢谢。

【问题讨论】:

    标签: django python-sphinx


    【解决方案1】:

    我不是 Sphinx 方面的专家。但答案很明确,恕我直言。

    首先,错误消息显示模块不可导入。这意味着某些 .py 文件中的 import 语句是错误的。

    可能的原因:

    1. 旧版导入语句
    2. 不正确的导入语句
      • 级别深度导入
      • 错字
    3. 模块不在工作 python 路径上

    2.b 特别有趣。如果您在 myapp/mysubapp/models.py 中,并且要导入 myapp/views.py,则需要提供以下语句: p>

    # myapp/mysubapp/models.py
    import mysite.myapp.view         # correct
    import myapp.view                # incorrect
    

    检查每个警告消息,并查看每个对应的 .py 文件。找到相应的导入语句,并仔细检查可用性。

    现在回到 virtualenv 问题。在我看来,您的 virtualenv 也可能是一个主要原因。只看第一个错误:

    ImportError: No module named webclient.__init__
    

    这是一个该死的问题。仔细检查您的路径变量是否已正确设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-19
      • 1970-01-01
      • 2012-05-06
      • 1970-01-01
      相关资源
      最近更新 更多