天天看點

Python程式設計:pipenv管理項目虛拟環境

項目位址: https://github.com/pypa/pipenv

安裝

$ pip install pipenv      

使用

在項目根目錄執行以下語句,常用指令如下

$ pipenv --python 3.6 # 使用python 3.6 建立虛拟環境

$ pipenv install   # 初始化環境

$ pipenv install requests           # 安裝子產品
$ pipenv install requests --dev  # 開發環境依賴
 
$ pipenv --rm # 移除環境
 
$ pipenv graph  # 檢視已安裝的包
 
$ pipenv shell  # 啟動shell

$ pipenv uninstall --all  # 解除安裝所有

$ pipenv run python hello.py  # 運作腳本

$ pipenv -h  # 檢視幫助      

會多出來兩個檔案Pipfile,Pipfile.lock

修改pip源

Pipfile檔案用記事本打開修改url後面的值為清華大學源

[[source]]
# url = "https://pypi.org/simple"
url = "https://pypi.tuna.tsinghua.edu.cn/simple/"      

經過多次嘗試,發現坑比較多, 還是選擇pyenv