轉帖|使用教程|編輯:鮑佳佳|2021-06-16 10:08:44.680|閱讀 369 次
概述:本系列教程主要是做一個有依賴的項目和虛擬環境,然后做一個簡單的Sphinx網站。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
PyCharm是一種Python IDE,其帶有一整套可以幫助用戶在使用Python語言開發時提高其效率的工具。此外,該IDE提供了一些高級功能,以用于Django框架下的專業Web開發。本教程為關于創建一個 Sphinx網站系列教程。
本系列教程主要是做一個有依賴的項目和虛擬環境,然后做一個簡單的Sphinx網站。
Sphinx可以被添加到現有的Python應用程序或庫中,以提供文檔。但它也可以作為項目本身使用--比如說,一個網站。在本教程的步驟中,我們用Sphinx啟動一個新的網站,作為一個新的Python項目。
本教程將模擬為一家名為 "Schlockchain "的虛構公司建立網站。該公司顯然有很多想要進行的營銷活動。它也有一些代碼和--顯然--它想展示的專利。風險資本家想要一個網站,創始人并不是真正的技術人員,所以他們想使用Markdown。
首先,讓我們創建一個新目錄并將其更改為:
$ mkdir schlockchain $ cd schlockchain
注意:我們在本教程中使用 macOS/Linux/WSL 命令 shell 語法。
Python 推薦項目使用虛擬環境進行隔離。Real Python 有一個關于虛擬環境的很好的入門讀物,包括為什么、什么、以及如何。讓我們建立一個新的虛擬環境,存儲在我們項目的 .venv 目錄中。然后我們將 "激活 "它,這將改變我們的命令路徑,使之首先在這個虛擬環境的 bin 中查找。
$ python3 -m venv .venv $ source .venv/bin/activate
pip是 Python 的軟件包安裝程序。更新您的pip. 請注意,在下面,由于source上面的行,我們的 shell 正在使用python3虛擬環境目錄:
$ pip install --upgrade pip
我們新的空白 Python 項目現在已準備好安裝 Sphinx。
在您喜歡的編輯器中打開此項目目錄。我們將通過創建一個requirements.txt文件來安裝我們的包,以存儲我們的依賴項列表。現在,將以下行放入這個新文件中:
sphinx
我們現在可以使用激活的 shellpip來安裝我們的依賴項:
$ pip install -r requirements.txt
Sphinx 本身有許多依賴項,因此獲取所有包可能需要一段時間。完成后,讓我們確認 Sphinx 已安裝并在我們的路徑上:
$ which sphinx-quickstart [some path prefix].venv/bin/sphinx-quickstart
Sphinx 有許多命令(用 Python 實現)。它們被添加到您的虛擬環境bin目錄中。如果你看到sphinx-quickstart,你的狀態很好。
Sphinx有一個網站生成器的命令,叫做sphinx-quickstart,現在在你的虛擬環境的bin目錄中。
讓我們運行它并回答一些問題,接受大多數默認值(注意...是隱藏我的目錄路徑):
$ 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.
下面是我們的目錄在運行后的樣子:
(.venv) schlockchain pauleveritt$ ls Makefile _templates make.bat _build conf.py requirements.txt _static index.rst
關于其中一些目錄項:
conf.py是Sphinx配置文件
index.rst 是我們網站頂部的“主頁”或文檔
Makefile(make.bat適用于 Windows)是一個簡單的命令運行程序
_build(生成的文件)、_static(自定義站點資產)和_templates(自定義模板)存在空目錄。
注意:如果您使用的是 PyCharm 等 IDE,請將_build目錄標記為已忽略。
好了這就是今天的內容了,下一節將繼續講解如何構建網站。不要忘了在評論與我們分享您的想法和建議,慧都作為IntelliJ IDEA正版合作商,我們推出"軟件國產化服務季"活動(點擊查看詳情)!現PyCharm正版授權在線訂購最高立減3000元!低至1333!還有多種授權方式供你選擇。
====================================================
想要了解或購買PyCharm正版授權的朋友,歡迎
JetBrain技術交流群現已開通,QQ搜索群號“786598704”或者掃描下方二維碼即可加入
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自: