AVt天堂网 手机版,亚洲va久久久噜噜噜久久4399,天天综合亚洲色在线精品,亚洲一级Av无码毛片久久精品

當(dāng)前位置:首頁 > 科技  > 軟件

Requirements.txt你真的清楚嗎

來源: 責(zé)編: 時(shí)間:2023-11-10 17:07:50 280觀看
導(dǎo)讀很多Python開源項(xiàng)目在環(huán)境搭建教程中都會(huì)提供requirements.txt,所以有必要搞清楚這到底有什么作用以及一些細(xì)節(jié)須知,花幾分鐘一起看看吧!1.如何安裝requirements.txt中的所有內(nèi)容requirements.txt中包含項(xiàng)目所需依賴的所

很多Python開源項(xiàng)目在環(huán)境搭建教程中都會(huì)提供requirements.txt,所以有必要搞清楚這到底有什么作用以及一些細(xì)節(jié)須知,花幾分鐘一起看看吧!lVV28資訊網(wǎng)——每日最新資訊28at.com

lVV28資訊網(wǎng)——每日最新資訊28at.com

1.如何安裝requirements.txt中的所有內(nèi)容

requirements.txt中包含項(xiàng)目所需依賴的所有庫(kù),如:lVV28資訊網(wǎng)——每日最新資訊28at.com

library-one==1.0.1library-two==3.1.4library-three==100.1.0

要一鍵安裝txt中所指定的3個(gè)庫(kù),我們可以運(yùn)行以下命令:lVV28資訊網(wǎng)——每日最新資訊28at.com

pip install -r requirements.txt

這將自動(dòng)安裝 requirements.txt 中指定的每行庫(kù)及相應(yīng)版本。lVV28資訊網(wǎng)——每日最新資訊28at.com

2.如何生成requirements.txt

假設(shè)現(xiàn)在其他人需要運(yùn)行自己的代碼,那么需要確保兩者運(yùn)行環(huán)境一致,首先在項(xiàng)目Python環(huán)境的終端中運(yùn)行如下命令:lVV28資訊網(wǎng)——每日最新資訊28at.com

pip freeze

該命令將在終端中打印出每個(gè)安裝的每個(gè)第三方庫(kù)以及相應(yīng)版本,如:lVV28資訊網(wǎng)——每日最新資訊28at.com

absl-py==1.4.0altair==5.0.1anyio==3.6.2appdirs==1.4.4appnope==0.1.3argon2-cffi==21.3.0

是不是感覺這就是requirements.txt文件中的內(nèi)容。lVV28資訊網(wǎng)——每日最新資訊28at.com

現(xiàn)在希望將這些內(nèi)容寫入文本文件中,但又不想手動(dòng)復(fù)制粘貼它,可以使用以下命令將其寫入:lVV28資訊網(wǎng)——每日最新資訊28at.com

pip freeze > requirements.txt

該語句的作用是將pip freeze輸出的所有內(nèi)容寫入名為requirements.txt的文本文件中,lVV28資訊網(wǎng)——每日最新資訊28at.com

這樣,requirements.txt文件制作完畢,接下來是一些須知。lVV28資訊網(wǎng)——每日最新資訊28at.com

3.最好使用虛擬環(huán)境創(chuàng)建requirements.txt

當(dāng)我們使用pip freeze時(shí),每個(gè)安裝的庫(kù)都會(huì)出現(xiàn)在你的requirements.txt中。lVV28資訊網(wǎng)——每日最新資訊28at.com

這可能會(huì)很輸出肥腸多的內(nèi)容,如果項(xiàng)目只需要幾個(gè)主要庫(kù),但requirements.txt會(huì)安裝另外100個(gè)不必要的庫(kù),該怎么辦?lVV28資訊網(wǎng)——每日最新資訊28at.com

使用 Python 虛擬環(huán)境!lVV28資訊網(wǎng)——每日最新資訊28at.com

python -m venv env    # create a virtual environment called 'env'
# activating our Python virtual environmentenv/Scripts/activate.bat    # Windowssource env/bin/activate     # MacOS/Linux

創(chuàng)建新的虛擬環(huán)境后,干凈又衛(wèi)生,沒有安裝任何內(nèi)容。因此,安裝項(xiàng)目所需的主要庫(kù)后使用pip freeze,最終出現(xiàn)在requirements.txt中的內(nèi)容將僅包含這些主要內(nèi)容。lVV28資訊網(wǎng)——每日最新資訊28at.com

4.省略requirements.txt中的版本會(huì)如何

這是一個(gè)規(guī)范的 requirements.txt:lVV28資訊網(wǎng)——每日最新資訊28at.com

numpy==1.23.5pandas==1.5.2

將安裝具有特定版本的numpy與pandas。lVV28資訊網(wǎng)——每日最新資訊28at.com

如下是一個(gè)沒有版本的requirements.txt:lVV28資訊網(wǎng)——每日最新資訊28at.com

numpypandas

將安裝最新版本的numpy與pandas,如果項(xiàng)目中的某些庫(kù)是沒有版本依賴的可以這樣做。lVV28資訊網(wǎng)——每日最新資訊28at.com

5.不一定要命名為requirements.txt

pip install -r requirements.txt
  1. -r表示read
  2. requirements.txt只是一個(gè)不符合慣例命名的任意文本文件

實(shí)際上,可以將其命名為任何名稱,只要它是有效的文本文件名即可,如:lVV28資訊網(wǎng)——每日最新資訊28at.com

pip install -r a.txt

但不建議這樣做。lVV28資訊網(wǎng)——每日最新資訊28at.com

6.requirements.txt可以包含其他requirements.txt文件

假設(shè)我們有2個(gè)requirements.txt文件:lVV28資訊網(wǎng)——每日最新資訊28at.com

requirements.txtrequirements_windows.txt
  • requirements.txt包含主要內(nèi)容
  • requirements_windows.txt包含專門的Windows庫(kù)

我們希望requirements_windows.txt也包含requirements.txt內(nèi)的內(nèi)容,可以在requirements_windows.txt中這樣寫:lVV28資訊網(wǎng)——每日最新資訊28at.com

library-onelibrary-two-r requirements.txt
  • 首先library-one和library-two將被安裝
  • 最后requirements.txt中的所有內(nèi)容也將被安裝

本文鏈接:http://www.tebozhan.com/showinfo-26-20051-0.htmlRequirements.txt你真的清楚嗎

聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。郵件:2376512515@qq.com

上一篇: Flv.js 直播簡(jiǎn)單?延遲和卡頓你怎么處理

下一篇: 十大數(shù)據(jù)科學(xué)Python庫(kù),你用過幾個(gè)?

標(biāo)簽:
  • 熱門焦點(diǎn)
Top