由於某些不可抗因素,Python官方的包在國內有時無法訪問或出現網路不穩定現象。為瞭解決這個問題就需要將Pip中內建的源地址修改為鏡像地址。
目前收集的比較好的鏡像地址有:
http://pypi.v2ex.com/simple/
http://pypi.douban.com/simple/
http://mirrors.aliyun.com/pypi/simple/
直接修改配置的方法:
windows系統
在使用者檔案夾下建立pip目錄,並在pip目錄下建立pip.in檔案(%HOMEPATH%\pip\pip.ini),檔案中添加如下內容:
[global]
trusted-host=mirrors.aliyun.com
index-url=http://mirrors.aliyun.com/pypi/simple/
備忘:index-url即源地址,trusted-host為源地址的網域名稱,由於國內的源鏡像都為使用https協議,所以如果不添加信任域就會報:
This repository located at mirrors.aliyun.com is not a trusted host, if this repository is available via HTTPS it is recommend to use HTTPS instead, otherwise you may silence this warning with ‘–trusted-host mirrors.aliyun.com’.
DEPRECATION: Implicitly allowing locations which are not hosted at a secure origin is deprecated and will require the use of –trusted-host in the future.
Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages
Linux系統
唯一與Windows系統不同的是設定檔的地址,linux的檔案在~/.pip/pip.conf
不改設定檔,每次手動指定:
pip install -i http://<mirror>/simple <package>
例如
pip install -i http://pypi.douban.com/simple simplejson