一招解決python pip install 安裝庫失敗
PIP是python強大的安裝利器,但是我們經常遇到安裝庫失敗的問題,以下本人覺得最有效的解決方法:
1.打開 https://www.lfd.uci.edu/~gohlke/pythonlibs網站,
2.搜索(CTRL+F)需要安裝的庫的名稱,比如pandas
3.找到對應自己系統的版本並下載,cp后面的數字時python的版本,如cp36代表python3.6版本,WIN后面的數字32/64表示32或者64位系統;
4.下載后,使用pip install +路徑文件名安裝,例如
pip install c:\pandas‑0.23.4‑cp36‑cp36m‑win_amd64.whl
用pip install不能成功安裝時的處理方法
我在安裝pymysql時,怎么也不能安裝成功:
先用pip install pymysql安裝:
總是出現錯誤:Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000238CE8677B8>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/pymysql/
不成功,我又嘗試用conda install pymysql安裝:
還是不成功,又嘗試用python -m pip install pymysql安裝:
最后發現實際上是網絡慢,要安裝的包不能順利下載造成的。
解決辦法:
pip install pymysql -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
這些安裝的數據包好幾個網站都有鏡像:
阿里雲 http://mirrors.aliyun.com/pypi/simple/
中國科技大學 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/
中國科學技術大學 http://pypi.mirrors.ustc.edu.cn/simple/
使用方法很簡單,直接 -i 加 url 即可!如下:
pip install web.py
-
i http:
/
/
pypi.douban.com
/
simple
或者
pip install web.py -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
也可以把這些包源設置成默認的,方法是修改pip.ini文件的配置:比如
-
[
-
index-url = http: //pypi.douban.com/simple
-
[
-
trusted-host=pypi.douban.com