pip使用国内镜像源解决报错Retrying

2022年08月03日 370点热度 0人点赞 0条评论

how-to-install-pip-on-windows.png

pip安装第三方库时报错如果出现这样的报错Retrying (Retry(total=1, 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 'ProxyError('Cannot connect to proxy.', NewConnection

Option 1:直接使用镜像源下载

pip安装的库后面加上 -i: 镜像源地址 http://mirrors.aliyun.com/pypi/simple/和
--trusted-host: host就是指http://和/之间的部分,即mirrors.aliyun.com

如下为使用这种方式安装pandas

pip install pandas -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

常见国内镜像源


清华大学: -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn 豆瓣:-i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com 阿里云:-i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

Option 2:设置镜像源全局默认

如果不想每次这么麻烦,可以一次性设为全局默认。方法如下:

  • window 系统中在如下路径C:\Users\xxx 新建一个文件夹,在文件夹里新建pip.ini文件,将下面内容复制到pip.ini文件中,并保存。
[global]
index-url = http://mirrors.aliyun.com/pypi/simple
[install]
trusted-host=mirrors.aliyun.com

  • 使用cmd cd进入这个文件夹下使用pip install 开始安装

如下为使用这种方式安装pandas

2022-08-03_172403.png

KOgoal

文章评论