WARNING: Retrying (Retry(total=4, connect=None,...after connection broken by ‘SSLError(SSLEOFError
1. 故障描述
问题:在使用python时,我们经常需要安装一些包,但是在终端prompt或者cmd界面下,使用pip install xxx(包)的时候,可能会出现如下的报错信息:
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)'))': /simple/bista/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)'))': /simple/bista/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)'))': /simple/bista/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)'))': /simple/bista/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)'))': /simple/bista/
Could not fetch URL https://pypi.org/simple/bista/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/bista/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1131)'))) - skipping
ERROR: Could not find a version that satisfies the requirement bista (from versions: none)
ERROR: No matching distribution found for bista
**问题原因:**pip源由于国内、国外墙的原因,连接证书验证失败。
2. 永久解决源和信任问题
2.1 Windows下指定源并信任
-
找到系统盘下C:\Users\用户名\AppData\Roaming
-
查看在Roaming文件夹下有没有一个pip文件夹,如果没有创建一个;
-
进入pip文件夹,创建一个pip.ini文件;
-
使用记事本的方式打开pip.ini文件,写入:
[global]
index-url = http://mirrors.aliyun.com/pypi/simple # 指定下载源
trusted-host = mirrors.aliyun.com # 指定域名
2.2 Ubuntu下指定源并信任
找到~/.pip/pip.conf,如果不存在就创建,加入内容如下
cd ~/.pip/pip.conf
写入下述代码
[global]
timeout = 10 # 设置超时,单位s
index-url = http://mirrors.aliyun.com/pypi/simple/ # 指定优先下载源
extra-index-url= http://pypi.douban.com/simple/ # 第二下载源
[install]
trusted-host=
mirrors.aliyun.com
pypi.douban.com
pypi.tuna.tsinghua.edu.cn
3. 代码式问题解决
这个需要每次在pip install xxx(包)之后加一串信任和源名称的代码,相对来说较为直截了当。
调用国内的源镜像,并信任指定的源
国内的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/
标准示意代码如下:
pip install xxx -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com