轉(zhuǎn)帖|使用教程|編輯:鮑佳佳|2021-06-16 10:08:44.680|閱讀 369 次
概述:本系列教程主要是做一個(gè)有依賴的項(xiàng)目和虛擬環(huán)境,然后做一個(gè)簡(jiǎn)單的Sphinx網(wǎng)站。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
PyCharm是一種Python IDE,其帶有一整套可以幫助用戶在使用Python語言開發(fā)時(shí)提高其效率的工具。此外,該IDE提供了一些高級(jí)功能,以用于Django框架下的專業(yè)Web開發(fā)。本教程為關(guān)于創(chuàng)建一個(gè) Sphinx網(wǎng)站系列教程。
本系列教程主要是做一個(gè)有依賴的項(xiàng)目和虛擬環(huán)境,然后做一個(gè)簡(jiǎn)單的Sphinx網(wǎng)站。
Sphinx可以被添加到現(xiàn)有的Python應(yīng)用程序或庫(kù)中,以提供文檔。但它也可以作為項(xiàng)目本身使用--比如說,一個(gè)網(wǎng)站。在本教程的步驟中,我們用Sphinx啟動(dòng)一個(gè)新的網(wǎng)站,作為一個(gè)新的Python項(xiàng)目。
本教程將模擬為一家名為 "Schlockchain "的虛構(gòu)公司建立網(wǎng)站。該公司顯然有很多想要進(jìn)行的營(yíng)銷活動(dòng)。它也有一些代碼和--顯然--它想展示的專利。風(fēng)險(xiǎn)資本家想要一個(gè)網(wǎng)站,創(chuàng)始人并不是真正的技術(shù)人員,所以他們想使用Markdown。
首先,讓我們創(chuàng)建一個(gè)新目錄并將其更改為:
$ mkdir schlockchain $ cd schlockchain
注意:我們?cè)诒窘坛讨惺褂?macOS/Linux/WSL 命令 shell 語法。
Python 推薦項(xiàng)目使用虛擬環(huán)境進(jìn)行隔離。Real Python 有一個(gè)關(guān)于虛擬環(huán)境的很好的入門讀物,包括為什么、什么、以及如何。讓我們建立一個(gè)新的虛擬環(huán)境,存儲(chǔ)在我們項(xiàng)目的 .venv 目錄中。然后我們將 "激活 "它,這將改變我們的命令路徑,使之首先在這個(gè)虛擬環(huán)境的 bin 中查找。
$ python3 -m venv .venv $ source .venv/bin/activate
pip是 Python 的軟件包安裝程序。更新您的pip. 請(qǐng)注意,在下面,由于source上面的行,我們的 shell 正在使用python3虛擬環(huán)境目錄:
$ pip install --upgrade pip
我們新的空白 Python 項(xiàng)目現(xiàn)在已準(zhǔn)備好安裝 Sphinx。
在您喜歡的編輯器中打開此項(xiàng)目目錄。我們將通過創(chuàng)建一個(gè)requirements.txt文件來安裝我們的包,以存儲(chǔ)我們的依賴項(xiàng)列表。現(xiàn)在,將以下行放入這個(gè)新文件中:
sphinx
我們現(xiàn)在可以使用激活的 shellpip來安裝我們的依賴項(xiàng):
$ pip install -r requirements.txt
Sphinx 本身有許多依賴項(xiàng),因此獲取所有包可能需要一段時(shí)間。完成后,讓我們確認(rèn) Sphinx 已安裝并在我們的路徑上:
$ which sphinx-quickstart [some path prefix].venv/bin/sphinx-quickstart
Sphinx 有許多命令(用 Python 實(shí)現(xiàn))。它們被添加到您的虛擬環(huán)境bin目錄中。如果你看到sphinx-quickstart,你的狀態(tài)很好。
Sphinx有一個(gè)網(wǎng)站生成器的命令,叫做sphinx-quickstart,現(xiàn)在在你的虛擬環(huán)境的bin目錄中。
讓我們運(yùn)行它并回答一些問題,接受大多數(shù)默認(rèn)值(注意...是隱藏我的目錄路徑):
$ sphinx-quickstart Welcome to the Sphinx 3.2.1 quickstart utility. Please enter values for the following settings (just press Enter to accept a default value, if one is given in brackets). Selected root path: . You have two options for placing the build directory for Sphinx output. Either, you use a directory "_build" within the root path, or you separate "source" and "build" directories within the root path. > Separate source and build directories (y/n) [n]: The project name will occur in several places in the built documentation. > Project name: Schlockchain > Author name(s): Paul Everitt <pauleveritt@me.com> > Project release []: If the documents are to be written in a language other than English, you can select a language here by its language code. Sphinx will then translate text that it generates into that language. For a list of supported codes, see //www.sphinx-doc.org/en/master/usage/configuration.html#confval-language. > Project language [en]: Creating file /.../schlockchain/conf.py. Creating file /.../schlockchain/index.rst. Creating file /.../schlockchain/Makefile. Creating file /.../schlockchain/make.bat. Finished: An initial directory structure has been created. You should now populate your master file /.../schlockchain/index.rst and create other documentation source files. Use the Makefile to build the docs, like so: make builder where "builder" is one of the supported builders, e.g. html, latex or linkcheck.
下面是我們的目錄在運(yùn)行后的樣子:
(.venv) schlockchain pauleveritt$ ls Makefile _templates make.bat _build conf.py requirements.txt _static index.rst
關(guān)于其中一些目錄項(xiàng):
conf.py是Sphinx配置文件
index.rst 是我們網(wǎng)站頂部的“主頁”或文檔
Makefile(make.bat適用于 Windows)是一個(gè)簡(jiǎn)單的命令運(yùn)行程序
_build(生成的文件)、_static(自定義站點(diǎn)資產(chǎn))和_templates(自定義模板)存在空目錄。
注意:如果您使用的是 PyCharm 等 IDE,請(qǐng)將_build目錄標(biāo)記為已忽略。
好了這就是今天的內(nèi)容了,下一節(jié)將繼續(xù)講解如何構(gòu)建網(wǎng)站。不要忘了在評(píng)論與我們分享您的想法和建議,慧都作為IntelliJ IDEA正版合作商,我們推出"軟件國(guó)產(chǎn)化服務(wù)季"活動(dòng)(點(diǎn)擊查看詳情)!現(xiàn)PyCharm正版授權(quán)在線訂購(gòu)最高立減3000元!低至1333!還有多種授權(quán)方式供你選擇。
====================================================
想要了解或購(gòu)買PyCharm正版授權(quán)的朋友,歡迎
JetBrain技術(shù)交流群現(xiàn)已開通,QQ搜索群號(hào)“786598704”或者掃描下方二維碼即可加入
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自: