解决:WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None))

本文讲述了在使用pip安装Python库时遇到NewConnectionError的问题,主要原因是网络不稳定。文章提供了更换下载源、设置超时时间、检查网络环境以及离线安装等解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


解决:WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None))





背景

在使用之前的代码时,报错:
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fbf5e1ffac8>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution’)':
/packages/ad/fd/6bfe87920d7f4fd475acd28500a42482b6b84479832bdc0fe9e589a60ceb/Keras-2.3.1-py2.py3-none-any.whl



报错问题


WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fbf5e1ffac8>: 
Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': 
/packages/ad/fd/6bfe87920d7f4fd475acd28500a42482b6b84479832bdc0fe9e589a60ceb/Keras-2.3.1-py2.py3-none-any.whl

截图如下:

在这里插入图片描述



报错翻译

主要报错信息内容翻译如下所示:


WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fbf5e1ffac8>: 
Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': 
/packages/ad/fd/6bfe87920d7f4fd475acd28500a42482b6b84479832bdc0fe9e589a60ceb/Keras-2.3.1-py2.py3-none-any.whl

翻译:


 警告:在连接中断后重试(Retry(total=4, connect=None, read=None, redirect=None, status=None)) NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7fbf5e1ffac8>: 
 Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': 
 /packages/ad/fd/6bfe87920d7f4fd475acd28500a42482b6b84479832bdc0fe9e589a60ceb/Keras-2.3.1-py2.py3-none-any.whl



报错原因

经过查阅资料,发现是在安装codecs,theano等模块时,经常出现这个问题。主要原因是网络连通性不好,网络连接不稳定(网络问题)。所以需要自己设定或者更换安装源。

小伙伴们按下面的解决方法即可解决!!!



解决方法

要解决这个错误,有如下几种方法:

方法一:更换下载源

修改默认的pip安装源请参考:修改默认的pip安装源(修改默认的PyPI安装源)

临时使用常用的国内源下载,例如:

清华源:

pip install xxxx -i https://pypi.tuna.tsinghua.edu.cn/simple

豆瓣源:

pip install xxxx -i https://pypi.douban.com/simple

附,国内各大源列表:

名称地址
阿里https://mirrors.aliyun.com/pypi/simple
豆瓣http://pypi.douban.com/simple/
清华大学https://pypi.tuna.tsinghua.edu.cn/simple
中国科学技术大学https://pypi.mirrors.ustc.edu.cn/simple
华中理工大学http://pypi.hustunique.com/simple
山东理工大学http://pypi.sdutlinux.org/simple
网易https://mirrors.163.com/pypi/simple/
腾讯https://mirrors.cloud.tencent.com/pypi/simple

方法二:设置超时时间

使用超时时间设置,例如:

pip --default-timeout=500 install xxxx 
pip --default-timeout=500 install -U pip xxxx

注意,等号后面的超时时间值可以调整。

方法三:换源+设置超时

同时更换国内源 + 设置超时时间,(就是有时仍慢了点,但仍有可能传输中断):

pip --default-timeout=500 install xxxx -i https://pypi.tuna.tsinghua.edu.cn/simple

或者

pip --default-timeout=500 install xxxx -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

注意:如果还是超时了,可以设置更大的超时时间数

在这里插入图片描述

方法四:检查或更换网络环境

检查下是否开启代理或者VPN,将其关闭再使用国内镜像进行尝试看看是否可以解决,我这边有过代理开启导致网络太慢而报错的。

或者干脆换一个网络条件更好的网络环境。

方法五:离线安装

当网络条件太差并且没有别的选择时,而上述方法都行不通,就只能手动下载离线安装包,进行离线安装了。以catboost为例。

在这里插入图片描述

在这里插入图片描述

安装命令如下:

pip install catboost-0.24.2-cp36-none-win_amd64.whl



今天的分享就到此结束了

欢迎点赞评论关注三连

在这里插入图片描述

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

ninghes

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

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

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

打赏作者

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

抵扣说明:

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

余额充值