簡介
通常情況下定拟,使用easy_install和pip進(jìn)行包的安裝省時又省力逗嫡,因為這兩種方法都是從官方源直接下載到本地再安裝(若有緩存則使用緩存),國情特殊延窜,直接使用默認(rèn)配置的pip安裝速度往往非常慢需曾,或者經(jīng)常會出現(xiàn)timed out的錯誤。
針對國內(nèi)的情況呆万,最好的辦法是使用國內(nèi)的一些知名鏡像,例如:
阿里(我個人在使用): http://mirrors.aliyun.com/simple/
問題
我在使用的pip是當(dāng)下的最新版本8.1.2牡彻,直接使用http安裝或升級包的時候出爹,會收到pip的warning
以安裝numpy為例,執(zhí)行:
[sudo] pip install -i http://mirrors.aliyun.com/simple/ numpy
可能會出現(xiàn)以下warning:
Collecting numpy The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored.
If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwise you may silence this warning and allow it anyways with ‘–trusted-host mirrors.aliyun.com’.
Could not find a version that satisfies the requirement numpy (from versions: )
No matching distribution found for numpy
解決辦法有多重总寻,見下
單次使用
以阿里的源安裝numpy為例:
pip install numpy -i http://mirrors.aliyun.com/simple/ --trusted-host=mirrors.aliyun.com
有些朋友提到可以編輯.bashrc一類的文件添加alias來做到每次默認(rèn)添加后面這些參數(shù)渐行,但還有更省事的方法
修改pip.conf
在一般的Unix系統(tǒng)下铸董,這個文件位于 ~/.pip/pip.conf
若沒有.pip目錄可以自行創(chuàng)建
cd ~
mkdir .pip
cd .pip
touch pip.conf --- 這一步可省略
在該文件中添加以下內(nèi)容
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
然后保存退出即可
如果你有閑情逸致自己搭一個鏡像的話
http://doc.devpi.net/latest/
可以參考這個網(wǎng)站上的信息粟害,有非常詳細(xì)的搭建鏡像教程,不過需要能讀懂英文文檔哦~
備注
如果需要恢復(fù)默認(rèn)源套鹅,可以選擇刪除這個conf文件汰具,也可以直接更改index-url為Python官方的源
本文已在版權(quán)印備案,如需轉(zhuǎn)載請訪問版權(quán)印减牺。53664156