今天开始使用Sphinx生成python文档。我以前用Doxygen给C代码生成文档,所以这次特意花了点时间比较Sphinx和Doxygen。读了这篇文章之后我决定使用Sphinx Comparison of Python documentation generators。
Sphinx是生成python文档最受欢迎的工具,甚至Python 3 的官方文档也是用Sphinx生成的。在本文中我将和你分享怎么使用Sphinx。
安装
你可以在这里找到sphinx在不同平台的安装方法,我只简单介绍几个比较常用的:
Debian/Ubuntu
Python2$ apt-get install python-sphinx
Python3$ apt-get install python3-sphinx
用pip安装
可以用于Linux, MacOS以及windowspip install -U sphinx
用Git安装
可以用于Linux, MacOS以及windows$ git clone https://github.com/sphinx-doc/sphinx$ cd sphinx$ pip install .
设置和使用
启动sphinx
安装好Sphinx以后你可以在你的代码所在文件夹启动命令窗口并用以下命令启动sphinx:sphinx-quickstart
比如,这里我在名叫Python的文件夹里使用该命令。文件夹中有一个python的测试代码文件。
设置