python中pipenv的使用
1、使用前提
前提:假設(shè)我們在用戶目錄~下有一個項(xiàng)目叫my_project/
我們首先進(jìn)入項(xiàng)目目錄:
cd~/my_project
進(jìn)入項(xiàng)目后,如果直接執(zhí)行pipenvvinstall,pipen會根據(jù)系統(tǒng)默認(rèn)的python版本創(chuàng)建一個虛擬環(huán)境。(前提是這個項(xiàng)目中不存在現(xiàn)有的Pipfile,如果存在,它會根據(jù)Pipfile安裝Pipfile中記錄的相應(yīng)版本和依賴庫)。
但是我們在創(chuàng)建虛擬環(huán)境時通常會指定python版本,這需要匹配兩三個參數(shù):
-two使用python2創(chuàng)建虛擬環(huán)境。
-three使用python3創(chuàng)建虛擬環(huán)境。
pipenvinstall--three#需要確保系統(tǒng)中存在python3版本
2、實(shí)例
下面是執(zhí)行后的輸出信息:
Creatingavirtualenvforthisproject…
Using/usr/local/bin/python3tocreatevirtualenv…
#這里可以看到繼承自哪個python版本
?Runningvirtualenvwithinterpreter/usr/local/bin/python3Usingbaseprefix'/usr/local'
Newpythonexecutablein/root/.local/share/virtualenvs/my_project-dhpIKgdN/bin/python3
Alsocreatingexecutablein/root/.local/share/virtualenvs/my_project-dhpIKgdN/bin/python
Installingsetuptools,pip,wheel...done.
#這里可以看到虛擬環(huán)境安裝的位置
Virtualenvlocation:/root/.local/share/virtualenvs/my_project-dhpIKgdN
CreatingaPipfileforthisproject…
Pipfile.locknotfound,creating…
Locking[dev-packages]dependencies…
Locking[packages]dependencies…
UpdatedPipfile.lock(625834)!
InstallingdependenciesfromPipfile.lock(625834)…
?▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉0/0—00:00:00
Toactivatethisproject'svirtualenv,runthefollowing:
$pipenvshell#要激活該虛擬環(huán)境,執(zhí)行這條指令
以上就是python中pipenv的使用,希望能對大家有所幫助,更多Python學(xué)習(xí)教程請關(guān)注IT培訓(xùn)機(jī)構(gòu):千鋒教育。