1. 程式人生 > 其它 >將pip源更換到國內映象

將pip源更換到國內映象

用pip管理工具安裝庫檔案時,預設使用國外的原始檔,因此在國內的下載速度會比較慢,可能只有50KB/s。

比較常用的國內映象有:

(1)阿里雲 http://mirrors.aliyun.com/pypi/simple/
(2)豆瓣http://pypi.douban.com/simple/
(3)清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/
(4)中國科學技術大學 http://pypi.mirrors.ustc.edu.cn/simple/
(5)華中科技大學http://pypi.hustunique.com/

設定方法:(以清華映象為例)
(1)臨時使用:
可以在使用pip的時候,加上引數-i和映象地址(如
https://pypi.tuna.tsinghua.edu.cn/simple),
例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas,這樣就會從清華映象安裝pandas庫。

(2)永久修改,一勞永逸:
(a)Linux下,修改 ~/.pip/pip.conf (沒有就建立一個資料夾及檔案。資料夾要加“.”,表示是隱藏資料夾)
內容如下:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn

注意:新版ubuntu要求使用https源。

(b) windows下,直接在user目錄中建立一個pip目錄,如:C:\Users\xx\pip,然後新建檔案pip.ini,即 %HOMEPATH%\pip\pip.ini,在pip.ini檔案中輸入以下內容(以清華映象為例):

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn