简体   繁体   English

无法使用 Sphinx 和 Google 文档字符串创建文档

[英]Unable to create documentation with Sphinx and Google docstrings

I am writing a Python API and I have documented every class and function in the sources using Google docstring convention, which I find way more readable than the Sphinx convention.我正在编写一个 Python API,并且我使用Google 文档字符串约定在源代码中记录了每个类和函数,我发现它比 Sphinx 约定更具可读性。 I want to use Sphinx to build the documentation for my API.我想使用 Sphinx 为我的 API 构建文档。 There is an extension called Napoleon that supports Numpydoc and Google docstrings , so I tried to use it and I encountered several problems.有一个名为Napoleon的扩展支持NumpydocGoogle docstrings ,所以我尝试使用它并遇到了几个问题。 I am using Python 2.7.3 on Ubuntu 12.04.我在 Ubuntu 12.04 上使用 Python 2.7.3。

I have Sphinx 1.1.3 installed.我安装了 Sphinx 1.1.3。 I did the first steps for the doc ( sphinx-quickstart , with the autodoc enabled and a make file).我为文档做了第一步( sphinx-quickstart ,启用了autodoc和一个 make 文件)。 I read that before Sphinx 1.3, I had to add sphinxcontrib.napoleon as an extension in the conf.py of my doc.我在 Sphinx 1.3 之前读到过,我必须在我的文档的conf.py中添加sphinxcontrib.napoleon作为扩展名。 I did that, and got the error that the extension napoleon could not be found.我这样做了,但得到了找不到扩展napoleon的错误。 I downloaded it, installed it, and then I had the error that a certain package could not be found:我下载了,安装了,然后出现找不到某个包的错误:

Could not import extension sphinxcontrib.napoleon (exception: cannot import name six)无法导入扩展名 sphinxcontrib.napoleon(例外:无法导入名称六)

This was the name of a package in the requirement file, so I installed it.这是需求文件中的包名,所以我安装了它。 I had the same error with another package, I installed it also.我对另一个包有同样的错误,我也安装了它。 Now I have the same error but with "range":现在我有同样的错误,但有“范围”:

Could not import extension sphinxcontrib.napoleon (exception: cannot import name range).无法导入扩展名 sphinxcontrib.napoleon(例外:无法导入名称范围)。

I don´t know which package it is, I haven´t found it anywhere, so I´m stuck.我不知道它是哪个包,我在任何地方都找不到它,所以我被困住了。 I tried ´sphinx.ext.napoleon´ just in case but it couldn't find the extension, which was expected.我尝试了“sphinx.ext.napoleon”以防万一,但它找不到扩展名,这是预期的。

I wanted to try then with Sphinx 1.3 and ´sphinx.ext.napoleon´ that should be shipped with Sphinx.然后我想尝试使用 Sphinx 1.3 和应该随 Sphinx 一起提供的“sphinx.ext.napoleon”。 When installing with apt-get, I only get version 1.1.3, even after an update.使用 apt-get 安装时,我只能获得 1.1.3 版本,即使在更新后也是如此。 So I tried downloading directly and installing Sphinx 1.3, but got the following errors:于是尝试直接下载并安装Sphinx 1.3,却出现如下错误:

 Processing./Sphinx-1.3.4.tar.gz Complete output from command python setup.py egg_info: /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'entry_points' warnings.warn(msg) /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'extras_require' warnings.warn(msg) /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'include_package_data' warnings.warn(msg) /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'zip_safe' warnings.warn(msg) /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'install_requires' warnings.warn(msg)

It seems to be a problem with setuptools.好像是setuptools的问题。 I found this post and tried the solution but I cannot get it to work.我找到了这篇文章并尝试了解决方案,但我无法让它工作。

I know I could change all my docstring but that would take time and be less readable.我知道我可以更改我所有的文档字符串,但这会花费时间并且可读性较差。 I can try something else than Sphinx but Sphinx is the most common documentation tool for Python, that´s why I tried to stick with it.除了 Sphinx,我还可以尝试其他工具,但 Sphinx 是 Python 最常用的文档工具,这就是我尝试坚持使用它的原因。

How can I get a good documentation (still automatically) made from the Google docstring in my sources?我怎样才能从我的来源中的谷歌文档字符串中获得一份好的文档(仍然是自动的)?

range is a python built-in, whose behavior changed in python3 . rangepython内置的,其行为在python3中发生了变化。 There could be some fight between python , sphinx and napoleon versions/requirements ( sphinx 1.1.3 is rather old). pythonsphinxnapoleon版本/要求之间可能存在一些冲突( sphinx 1.1.3相当旧)。

With concern to your last question (automatic documentation), you should look into the autodoc extension.关于您的最后一个问题(自动文档),您应该查看autodoc扩展。 If you want even more automation, look into the apidoc script, which is included in sphinx > 1.1 .如果你想要更多的自动化,请查看apidoc脚本,它包含在sphinx > 1.1中。

It is not a direct solution/answer to your problem, but you could also use a more up-to-date and robust python distribution such as Anaconda (rather than the stale python in the Ubuntu repos), which would allow you to use the most recent napoleon and sphinx versions without much hassle.它不是您问题的直接解决方案/答案,但您也可以使用更新和更强大的python发行版,例如Anaconda (而不是 Ubuntu 存储库中陈旧的 python),这将允许您使用最新的napoleonsphinx版本没有太多麻烦。

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

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