记一次 linux python 用pip install 命令安装包失败原因及解决方案:Failed to establish a new connection: [Errno -2]

博主在虚拟机中安装Python环境时遇到pip安装包失败的问题,错误日志显示因无法连接到服务器。通过测试发现是外网访问受限。在修改了Linux的配置文件`/etc/resolv.conf`,添加了公共DNS后,外网访问恢复正常。随后pip安装成功,问题得到解决。
摘要由CSDN通过智能技术生成

前两天自己搭建了一套虚拟机,然后安装python3环境,当进行pip install安装时始终无法正常安装,一开始都是把安装包下载下来,然后进行python setup install 进行安装,但是实在太麻烦了,与是又寻找解决方案。
错误日志:

pip install fake-useragent
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f1c094e3dc0>: Failed to establish a new connection: [Errno -2] Name or service not known')': /simple/fake-useragent/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f1c094e3fd0>: Failed to establish a new connection: [Errno -2] Name or service not known')': /simple/fake-useragent/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f1c095021f0>: Failed to establish a new connection: [Errno -2] Name or service not known')': /simple/fake-useragent/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f1c095023d0>: Failed to establish a new connection: [Errno -2] Name or service not known')': /simple/fake-useragent/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f1c094e3ac0>: Failed to establish a new connection: [Errno -2] Name or service not known')': /simple/fake-useragent/
ERROR: Could not find a version that satisfies the requirement fake-useragent
ERROR: No matching distribution found for fake-useragent

然后看到有人说可能是因为外网连接不上导致,与是就进行了外放访问测试

[root@hadoop102 ~]# curl http://www.baidu.com
curl: (6) Could not resolve host: www.baidu.com

发现还真是这个问题,与是修改linux配置文件:/etc/resolv.conf

vim /etc/resolv.conf
# 加入下面两行代码
nameserver 114.114.114.114
nameserver 8.8.8.8

再次执行:curl http://www.baidu.com 发现可以正常访问了,然后就进行了pip install 测试,发现可以正常安装了,问题得以解决

参考:pip升级失败

kaggle中WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7a356dc338d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/keras-bert/ WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7a356dc33410>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/keras-bert/ WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7a356dc33290>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/keras-bert/ WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7a356dc33590>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/keras-bert/ WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7a356dc354d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/keras-bert/ ERROR: Could not find a version that satisfies the requirement keras_bert (from versions: none) ERROR: No matching distribution found for keras_bert
05-28
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值