對于Python開發的程式員而言,pip 裝軟體是很重要的環境準備步驟。但由于各種原因,連結官方鏡像往往速度不佳,這時,使用國内的鏡像不但可以提高下載下傳速度,更可以提高安裝成功率,降低安裝步驟耗時。
國内源:
Ubuntu 16+ 要求使用https源,不要忘記 http後面的 s 哦。
中國科技大學 https://pypi.mirrors.ustc.edu.cn/simple/
清華:https://pypi.tuna.tsinghua.edu.cn/simple
阿裡雲:https://mirrors.aliyun.com/pypi/simple/
華中理工大學:https://pypi.hustunique.com/
山東理工大學:https://pypi.sdutlinux.org/
單次使用:
可以在使用pip的時候加參數-i https://pypi.mirrors.ustc.edu.cn/simple/
栗子一枚:pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ requests,這樣就會從USTC這邊的鏡像去安裝requests庫。
持久化修改:
如果你在使用Linux,那麼可以修改 ~/.pip/pip.conf
内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
如果使用Windows上面的 Pip,則需要在使用者主目錄下建立一個pip.ini,存放同樣的内容。
C:\Users\xxxxx\pip.ini