Python pip源配置修改的例子

來源:互聯網
上載者:User

由於某些不可抗因素,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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.