问题描述
开了网络代理之后,python 的 pip 就无法安装包了,报如下错误:
$ pip install netsm
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
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:1123)'))': /simple/netsm/
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:1123)'))': /simple/netsm/
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:1123)'))': /simple/netsm/
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:1123)'))': /simple/netsm/
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:1123)'))': /simple/netsm/
Could not fetch URL https://pypi.tuna.tsinghua.edu.cn/simple/netsm/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.tuna.tsinghua.edu.cn', port=443): Max retries exceeded with url: /simple/netsm/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1123)'))) - skipping
ERROR: Could not find a version that satisfies the requirement netsm (from versions: none)
ERROR: No matching distribution found for netsm
原因分析
想必很多同学都和我一样,配置了 pip 源为国内的清华源或阿里源,这样下载包的速度会快,以清华源为例,配置方法如下:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
然而,配置清华源之后,pip 安装的时候就是从清华的镜像仓库来抓取安装包,但是清华的网络会对一些境外的网络代理做屏蔽或过滤,因此导致开了代理之后,pip 就无法安装包了。
解决方案
临时方案
临时方案就很简单了,直接把代理关了就行了。但你要安装很多包的话,就很麻烦,得反复的开关代理,推荐下面的永久解决方案。
永久方案
既然 pip 镜像源(无论还是清华,亦或是阿里)对代理服务器进行了屏蔽,那么我们访问镜像源的时候就不要走代理网络了。再系统的代理设置里面,直接将镜像源的域名做隔断处理:文章来源:https://www.toymoban.com/news/detail-714829.html
即在代理服务器设置里面,请勿对以下条目开头的地址使用代理服务器,以清华源为例,就是添加 pypi.tuna.tsinghua.edu.cn
,注意前面的分号 ;
。文章来源地址https://www.toymoban.com/news/detail-714829.html
到了这里,关于【Python】解决 pip 开了网络代理之后无法安装包的问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!