Python Sphinx使用例項及問題解決

2022-09-26 19:18:19 字數 1304 閱讀 9008

描述

使用 pip 安裝sphinx後,按照教程建立了乙個新的py檔案,如下

# run.py

def run(name):

"""this is how we run

:param name name of people who runs

"""print(name, 'hytpocbthis 程式設計客棧running')

隨後新建乙個目錄,使用 sphinx-quickstart 新建了sphinx環境,此時目錄結構如下:

- doc

- makefile

- build/

- make.bat

- source/

- run.py

此時進入 source目錄,在conf.py 中新增檔案路徑,如下:

import os

import sys

sys.path.insert(0, 程式設計客棧os.path.abspath('../..'))

然後在 doc 下執行下面命令:

make html

orsphinx-build -b html ./doc/source ./doc/build

發現兩個命令都可以正常生成文件的模版,但並沒有生成注釋;即有生成的html,但沒有**的注釋/api文件

嘗試解決

開始以往是版本不一致,就重新建了virtualenv,還是不行;

使用了乙個docker映象,重試,結果是同樣的錯誤

嘗試看非官方的教程,發現還需要更改 source 下的 index.rst;

例如我們的**檔案是 run.py ,需要把他加到 index.rst中,如下(run就是模組名稱):

api===.. automodule:: run

:members:

再次執行,發現還有錯,只不過提示不一樣了:提示

unknown directive type 「automodule」 or 「autoclass」

谷歌之,發現還要改乙個配置的地方;位於 conf.py 裡,增加乙個擴充套件……如下:

extensions = [

'sphinx.ext.autodoc'

]此處參考了 https://程式設計客棧stackoverflow.com/questions/13516404/sphinx-error-unknown-directive-type-automodule-or-autoclass

再次嘗試,終於成功了…

本文標題: python sphinx使用例項及問題解決

本文位址: /jiaoben/python/298675.html

Python Sphinx使用踩坑記錄

描述 使用 pip 安裝sphinx後,按照教程建立了乙個新的py檔案,如下 run.py defrun name this is how we run param name name of people who runs print name,is running 隨後新建乙個目錄,使用 sphi...

Python Sphinx使用踩坑記錄

使用 pip 安裝sphinx後,按照教程建立了乙個新的py檔案,如下 run.py def run name this is how we run param name name of people who runs print name,is running 隨後新建乙個目錄,使用 sphinx...

Response AddHeader使用例項收集

response.addheader refresh 60 url newpath newpage.asp 這等同於客戶機端元素 頁面轉向 response.status 302 object moved response.addheader location newpath newpage.asp...