Python下载库超时Connection to files.pythonhosted.org timed out问题解决(换源)

本文介绍了解决Python环境下pip更新超时的方法,通过更换国内镜像源,有效解决了因网络屏蔽导致的连接超时问题,提供了临时及永久换源的详细步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一年没用Python,这突然有节课老师让用Python,用就用吧,一来就是一个下马威,pip版本太低不支持,更新还更新不了!!!就是超时,官网也进不去,抓狂中!!!

按照提示命令更新,更新超时

哇呀呀呀,我们还是冷静下来分析以下问题吧,错误信息提示连接python库超时,官网也进不去

可能是因为国家对外网的屏蔽,所以我们无法访问到境外的python服务器,所以连接超时

 

既然猜到了这个问题,作者在此给出两个解决方案

1、翻墙

2、换源

翻墙就不必多说,作者在这里分享以下换源全过程(国内镜像地址总结在最后)

首先,在我这里需要先将pip更新到最新的版本,使用了一次临时换源命令 ,在pip命令后面加上  -i 国内镜像地址,如下

成功

接下来我要永久换源,让我以后下载库都从国内镜像下载,命令为pip config set global.index-url 国内镜像地址

在上图的目录下创建了pip.ini文件

然后随便下载一个库做实验

成功

 

总结

1、国内镜像大全

阿里云 http://mirrors.aliyun.com/pypi/simple/ 
  豆瓣(douban) http://pypi.douban.com/simple/ 
  清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/ 
  中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

2、换源命令

临时:pip命令+ -i  +镜像地址。例如 pip install numpy -i https://mirrors.aliyun.com/pypi/simple/

永久:在更新到最新版本pip后,pip config set global.index-url+国内镜像地址,例如  

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值