今天帮同学解决问题,出现的问题是:服务器linux下装任何包都会出现如下错误。
Looking in indexes: http://pypi.douban.com/simple
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7ff0c2571fd0>, ‘Connection to 10.250.94.253 timed out. (connect timeout=15)’)’: /simple/pip/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7ff0c258aa90>, ‘Connection to 10.250.94.253 timed out. (connect timeout=15)’)’: /simple/pip/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7ff0c258add0>, ‘Connection to 10.250.94.253 timed out. (connect timeout=15)’)’: /simple/pip/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7ff0c2520050>, ‘Connection to 10.250.94.253 timed out. (connect timeout=15)’)’: /simple/pip/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7ff0c25203d0>, ‘Connection to 10.250.94.253 timed out. (connect timeout=15)’)’: /simple/pip/
ERROR: Could not find a version that satisfies the requirement transformers (from versions: none)
ERROR: No matching distribution found for transformers
网上查找各种方法,都是建议切换镜像源。按照他们的教程使用conda修改了镜像源。
conda config --show channels
但是发现pip install 装包的时候仍然是以豆瓣的镜像源下载,一直会出现下面这句:
Looking in indexes: http://pypi.douban.com/simple
折腾了很久,发现该服务器上之前有人使用pip配置过镜像源:
pip config set global.index-url https://pypi.douban.com/simple/
所以,一直都是默认豆瓣镜像源。
解决办法:
使用下面的命令删掉这个文件,就可以使用其它镜像源。
pip config unset global.index-url
解决这个问题后,发现装包仍然是上述ConnectTimeoutError错误,一直在Retrying。
怀疑是服务器的网络问题,使用下面的命令测试网络:
ping www.baidu.com
PING www.a.shifen.com (120.232.145.144) 56(84) bytes of data.
64 bytes from 120.232.145.144 (120.232.145.144): icmp_seq=1 ttl=52 time=7.83 ms
64 bytes from 120.232.145.144 (120.232.145.144): icmp_seq=2 ttl=52 time=7.84 ms
64 bytes from 120.232.145.144 (120.232.145.144): icmp_seq=3 ttl=52 time=7.83 ms
64 bytes from 120.232.145.144 (120.232.145.144): icmp_seq=4 ttl=52 time=7.85 ms
64 bytes from 120.232.145.144 (120.232.145.144): icmp_seq=5 ttl=52 time=7.86 ms
^C
— www.a.shifen.com ping statistics —
5 packets transmitted, 5 received, 0% packet loss, time 4007ms
rtt min/avg/max/mdev = 7.832/7.846/7.869/0.013 ms
发现没有问题,继续使用下面的命令测试网络:
curl www.baidu.com
结果总是出现超时,在其他电脑或者本地电脑上不会出现超时的问题。
于是怀疑是网络出现了问题,能ping通但是curl不下来,可能是服务器的代理出现了问题(因为之前尝试过在服务器上科学上网)。
使用下面的命令的查看服务器的代理:
env | grep -I proxy
结果出现:
有代理,无法正常上网。
查找相关资料,使用解决本地代理问题的教程修改代理。
解决方法:
在服务器终端执行以下命令,临时将代理取消掉
export http_proxy=""
export https_proxy=""
然后重新装包,发现成功了。
参考资料:
【工具】pip和conda添加和删除镜像源