简体   繁体   English

Sphinx、Kivy 和 autodoc:创建文档的警告和问题

[英]Sphinx, Kivy and autodoc: warning and issues to create documentation

I would like to create documentation of my code in Sphinx.我想在 Sphinx 中创建我的代码文档。 I installed everything and made some simple trial that worked fine.我安装了所有东西并进行了一些简单的试用,效果很好。 (I run sphinx-quickstart, edit the conf.py to include modules' path, work with a tutorial to know how sphinx works etc. etc.) (我运行 sphinx-quickstart,编辑 conf.py 以包含模块的路径,使用教程了解 sphinx 的工作原理等等。)

Yet, my code import many Kivy libraries.然而,我的代码导入了许多 Kivy 库。 And when I want to create the documentation on module that import Kivy, it fails.当我想在导入 Kivy 的模块上创建文档时,它失败了。

For instance, if I have my main.py like this:例如,如果我的 main.py 是这样的:

#!/usr/bin/python
# -*- coding: utf-8 -*-

from kivy.app import App

def test_app(a,b):
    """ Test documentation """
    print a + b

if __name__ == '__main__':
    test_app(1,2)

Then, if I run然后,如果我跑

make clean && make html清理&&制作html

I have the following wanring (and no doc edited..):我有以下 wanring(没有编辑文档..):

WARNING: /home/math/drphytoscan/source/autodoc.rst:4: (WARNING/2) autodoc: failed to import module u'src.main';警告:/home/math/drphytoscan/source/autodoc.rst:4:(警告/2)autodoc:导入模块 u'src.main' 失败; the following exception was raised: Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 657, in import_object import (self.modname) File "/home/math/drphytoscan/source/src/main.py", line 14, in from kivy.app import App ImportError: No module named app引发了以下异常:Traceback(最近调用最后一次):文件“/usr/local/lib/python2.7/dist-packages/sphinx/ext/autodoc.py”,第 657 行,在 import_object import (self.modname ) 文件“/home/math/drphytoscan/source/src/main.py”,第 14 行,在 from kivy.app import App ImportError: No module named app

Note: If I erase the line:注意:如果我删除该行:

from kivy.app import App

it works.有用。 That shows that it comes from the Kivy lib import.这表明它来自 Kivy 库导入。

PS: I have Python 2.7.9, Kivy 1.9.1 and Sphinx 1.6.3 on a Debian Jessie PS:我在 Debian Jessie 上安装了 Python 2.7.9、Kivy 1.9.1 和 Sphinx 1.6.3

From the note at the top of the documentation for autodoc :autodoc 文档顶部的注释:

For Sphinx (actually, the Python interpreter that executes Sphinx) to find your module, it must be importable.为了让 Sphinx(实际上是执行 Sphinx 的 Python 解释器)找到您的模块,它必须是可导入的。 That means that the module or the package must be in one of the directories on sys.path – adapt your sys.path in the configuration file accordingly.这意味着模块或包必须位于 sys.path 的目录之一中——相应地调整配置文件中的 sys.path。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM