python安装库超时,修改pip源

错误描述

cmd输出的异常信息

Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting selenium

  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x000002BFE5592EF0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/selenium/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x000002BFE5592940>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/selenium/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x000002BFE55928D0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/selenium/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x000002BFE5592AC8>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/selenium/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x000002BFE5737BA8>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')': /simple/selenium/
  Could not find a version that satisfies the requirement selenium (from versions: )
No matching distribution found for selenium

pycharm安装库失败
在这里插入图片描述

错因分析

由于GFW的存在,当我们在使用pip下载安装某个库的时候,会遇到莫名其妙的网络问题,比如我初学就死活安装不上selenium库。

解决办法

临时修改

在使用pip的时候加参数-i,如下:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple 库名

永久修改

Linux下,修改~/.pip/pip.conf(或者创建一个),将index-url变量修改为所要更换的源地址:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

windows下
1.在user目录中创建一个pip目录,如C:\Users\xx\pip
在这里插入图片描述
2.新建文件pip.ini
在这里插入图片描述
写入如下内容:

[global]

timeout = 6000

index-url = https://pypi.tuna.tsinghua.edu.cn/simple/

trusted-host = mirrors.tsinghua.com

我在这用的是清华的镜像,附上一些其他好用的供大家选择

国内镜像

阿里云http://mirrors.aliyun.com/pypi/simple/
中国科技大学https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣http://pypi.douban.com/simple
中国科学院http://pypi.mirrors.opencas.cn/simple/
清华大学https://pypi.tuna.tsinghua.edu.cn/simple/
  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值