使用sphinx生成python项目文档

本文详细介绍了使用Sphinx工具从Python源代码自动生成文档的过程,包括安装Sphinx、配置环境、生成API文档及部署到GitHub Pages的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#1

pip install sphinx

#2

sphinx-quickstart

#3

修改 conf.py

import os
import sys
sys.path.insert(0, os.path.abspath('../..'))
#确保module可以找到 .e.g.
#sys.path.insert(0, os.path.abspath('../../sample_module'))

html_theme = 'classic'
#all themes : https://sphinx-themes.org/

extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage', 'sphinx.ext.napoleon']

#4生成module.rst

sphinx-apidoc -f -o source/ ../{module_name}/

确保模块包含在module.rst 文件中 。例如 ,

sphinx-apidoc -f -o source/ ../sample_module

生成后的module.rst为

sample_module
=============

.. toctree::
   :maxdepth: 4

   main


Edit index.rst

.. toctree::
   :maxdepth: 2
   :caption: Contents:

   modules


#5

make html

#6配置github页面

github page-> branch -> docs -> save

#7浏览文档地址

https://htmlpreview.github.io/?{your_github_url}

生成后的效果页面. https://htmlpreview.github.io/?https://github.com/iorilan/py_game_playground/blob/master/docs/html/index.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值