【问题标题】:Python: Sphinx Import Error: No modulePython:狮身人面像导入错误:没有模块
【发布时间】:2017-06-02 18:11:25
【问题描述】:

我的源代码在目录 - /usr/share/jupiter_api/jupiter_api/services/v1

狮身人面像文件 -

  1. /usr/share/jupiter-doc/index.rst -> 调用 jupiter_api.rst
  2. /usr/share/jupiter-doc/api/jupiter_api.rst

jupiter_api.rst 文件生成自动文档。

.. automodule:: accounts
   :members:

/usr/share/jupiter-doc/api/conf.py

sys.path.append(os.path.abspath('/jupiter_api/jupiter_api/servicesi/v1/'))

当我运行 make clean 和 make html 时,我收到以下错误消息 -

Removing everything under '_build'...

[ /usr/share/jupiter-doc/api ]
root@d1piap2077 > make html
Running Sphinx v1.6.2
making output directory...
/usr/lib/python2.7/site-packages/sphinx/util/requests.py:72: UserWarning: 
Some links may return broken results due to being unable to check the Server 
Name Indication (SNI) in the returned SSL cert against the hostname in the 
url requested. Recommended to install requests-2.4.1+.
'Some links may return broken results due to being unable to '
loading pickled environment... not yet created
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 1 source files that are out of date
updating environment: 1 added, 0 changed, 0 removed
reading sources... [100%] jupiter_api
WARNING: /usr/share/jupiter-doc/api/jupiter_api.rst:15: (WARNING/2) autodoc: 
failed to import module u'accounts'; the following exception was raised:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/sphinx/ext/autodoc.py", line 657, in 
import_object
    __import__(self.modname)
ImportError: No module named accounts
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] jupiter_api
generating indices... genindex
writing additional pages... search
copying static files... done
copying extra files... done
dumping search index in English (code: en) ... done
dumping object inventory... done
build succeeded, 1 warning.

Build finished. The HTML pages are in _build/html.

【问题讨论】:

    标签: python python-sphinx importerror


    【解决方案1】:

    你可能需要

    sys.path.insert(0, os.path.abspath('../jupiter_api/jupiter_api/services/v1/'))
    

    您可以在 conf.py 中使用 print(sys.path) 进行调试。

    啊,等一下,你的 conf.py 在jupiter_doc/api/ 之下,但index.rst 高一级。但是您的 Makefile 位于 conf.py 级别,那么您还需要一个 '../'。但我猜你的 conf.py 中的 master_docjupiter_api ?为什么index.rstconf.py 在您的文档中不在同一顶级?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多