天天看點

python pip 修改源

由于某些不可抗因素,Python官方的包在國内有時無法通路或出現網絡不穩定現象。為了解決這個問題就需要将Pip中自帶的源位址修改為鏡像位址。

目前收集的比較好的鏡像位址有:

http://pypi.v2ex.com/simple/

http://pypi.douban.com/simple/

http://mirrors.aliyun.com/pypi/simple/

直接修改配置的方法:

windows系統

在使用者檔案夾下建立pip目錄,并在pip目錄下建立pip.in檔案(%HOMEPATH%pippip.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

     本文轉自aaron428 51CTO部落格,原文連結:http://blog.51cto.com/aaronsa/1859600,如需轉載請自行聯系原作者