【Python】解决 pip 开了网络代理之后无法安装包的问题

问题描述

开了网络代理之后,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 镜像源(无论还是清华,亦或是阿里)对代理服务器进行了屏蔽,那么我们访问镜像源的时候就不要走代理网络了。再系统的代理设置里面,直接将镜像源的域名做隔断处理:

在这里插入图片描述
即在代理服务器设置里面,请勿对以下条目开头的地址使用代理服务器,以清华源为例,就是添加 pypi.tuna.tsinghua.edu.cn,注意前面的分号 ;

  • 21
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Xavier Jiezou

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值