Python使用pip方法安裝第三方包時,需要從 https://pypi.org/ 資源庫中下載,但是會面臨下載速度慢,甚至無法下載的尷尬。
使用國內鏡像自然是個好方法:
清華大學:https://pypi.tuna.tsinghua.edu.cn/simple
阿里雲:http://mirrors.aliyun.com/pypi/simple/
中國科學技術大學 : https://pypi.mirrors.ustc.edu.cn/simple
豆瓣:http://pypi.douban.com/simple/
我們可以直接在 pip 命令中使用 -i 參數來指定鏡像地址,例如:
使用清華鏡像源安裝 numpy 包:pip3 install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
永久生效需要做下配置:
linux:在用戶目錄下新建.pip/pip.conf,並編輯
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn
windows:在用戶目錄下新建pip.ini,並編輯內容同linux
比如我的:C:\Users\Administrator\AppData\pip\pip.ini
內容同linux:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn