報錯信息:
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x0581C150>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/numpy/
原因:請求超時,數據源有問題。
默認pip是使用Python官方的源,但是由於國外官方源經常被牆,導致不可用,我們可以使用國內的python鏡像源,從而解決Python安裝不上庫的煩惱。
解決辦法:
1、修改源(臨時):
可以在使用pip的時候在后面加上-i參數,指定pip源。
eg:
如果有如下報錯:
請使用命令:
pip install numpy -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
其他一些國內的pip源,如下:
阿里雲 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/
#### 注意后面要有/simple目錄!!! ####
2、修改源方法(永久修改):
linux:
修改 ~/.pip/pip.conf (沒有就創建一個), 內容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
windows:
直接在user目錄中創建一個pip目錄,如:C:\Users\xx\pip,新建文件pip.ini,
windows在%HOMEPATH%\pip\pip.ini中寫入
內容如下:
-
[global]
-
index-url = http://pypi.douban.com/simple
-
[install]
-
trusted-host=pypi.douban.com
這樣在使用pip來安裝時,會默認調用該鏡像。