將pip源更換到國內鏡像
用pip管理工具安裝庫文件時,默認使用國外的源文件,因此在國內的下載速度會比較慢,可能只有50KB/s。幸好,國內的一些頂級科研機構已經給我們准備好了各種鏡像,下載速度可達2MB/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/
注意:新版ubuntu要求使用https源。
- 設置方法:(以清華鏡像為例,其它鏡像同理)
(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
(b) windows下,直接在user目錄中創建一個pip目錄,如:C:\Users\xx\pip,然后新建文件pip.ini,即 %HOMEPATH%\pip\pip.ini,在pip.ini文件中輸入以下內容(以豆瓣鏡像為例):
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host = pypi.douban.com