轉載自:https://blog.csdn.net/furzoom/article/details/53897318
一、問題:
經常在使用Python的時候需要安裝各種模塊,而pip是很強大的模塊安裝工具,但是由於國外官方pypi經常被牆,導致不可用,所以我們最好是將自己使用的pip源更換一下,這樣就能解決被牆導致的裝不上庫的煩惱。
網上有很多可用的源,例如
豆瓣:http://pypi.douban.com/simple/
清華:https://pypi.tuna.tsinghua.edu.cn/simple
最近使用得比較多並且比較順手的是清華大學的pip源,它是官網pypi的鏡像,每隔5分鐘同步一次,地址爲 https://pypi.tuna.tsinghua.edu.cn/simple
1、臨時使用:
可以在使用pip的時候加參數
-i https://pypi.tuna.tsinghua.edu.cn/simple
例如: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple gevent
這樣就會從清華這邊的鏡像去安裝gevent庫。
2、 永久修改,一勞永逸:
(1) Linux下
修改 ~/.pip/pip.conf (沒有就創建一個), 修改 index-url至tuna,內容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
(2)Windows下
直接在user目錄中創建一個pip目錄,如:C:\Users\"用戶名"\pip,新建文件pip.ini,內容如下
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple