在采用默认 pip3 安装第三方库的时候,经常会出现超时的情况。
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
这时候就需要替换镜像源为国内的镜像源了。
pip3 install 库名 -i 镜像地址
示例:
pip3 install django-excel -i https://mirrors.aliyun.com/pypi/simple/
查看执行是否替换镜像,如下:
可以看到镜像已经替换阿里云的镜像。
打开我的电脑,在地址栏中输入 %APPDATA%
按回车跳转到目标目录。在目录下创建一个pip文件,再其内部创建一个pip.ini 文件。输入以下信息。以阿里云为例
[global]
timeout = 6000
index-url = https://mirrors.aliyun.com/pypi/simple/
trusted-host = mirrors.aliyun.com
注意:不管你用的是pip3还是pip,方法都是一样的,都是创建pip文件夹。
再次执行下载,查看下载的地址是否更换,如下:
可以看到下载镜像源已经变更为阿里云镜像了。
~/.pip/pip.conf
[root@server01 ~]# mkdir -p ~/.pip
[root@server01 ~]# touch ~/.pip/pip.conf
pip.conf
配置镜像源[global]
timeout = 6000
index-url = https://mirrors.aliyun.com/pypi/simple/
trusted-host = mirrors.aliyun.com
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有