前两天自己搭建了一套虚拟机,然后安装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升级失败

Logo

鸿蒙生态一站式服务平台。

更多推荐