Python学习:解决pip总是WARNING: Retrying (Retry(total=4...

本文分享了在Python环境中使用pip指令时遇到的连接超时问题解决方案,通过切换至国内pip源,如阿里云、中国科技大学等,有效避免了连接超时错误。同时,文章还提供了如何信任指定pip源的方法。

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

我在今天学习Python 3的过程中,遇到了一个头疼的问题,当我使用pip指令的时候总是告诉我,

 WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError...

通过我不懈的浏览器搜索,我发现了解决之道!

pip install [whatyouwant] -i url

没错,就是这个上述的指令,大家只要把[whatyouwant]替换成自己需要的包就好啦!搞定!
其实问题本身大家看报错就能看出来,主要就是连接超时了,所以我们只要用一些国内的pip源就可以完美的解决。
下面有几个国内的pip源,供大家参考:

阿里云 http://mirrors.aliyun.com/pypi/simple/

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

豆瓣(douban) http://pypi.douban.com/simple/

清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/

中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

举个例子看看怎么用的(假如我想要安装openpyxl的包):

pip install openpyxl -i http://pypi.douban.com/simple

这样就可以安装openpyxl的包啦。

如果很不幸,你出现了下面这个问题,

WARNING: The repository located at pypi.douban.com is not a trusted or secure host and is being ignored. 
If this repository is available via HTTPS we recommend you use HTTPS instead, 
otherwise you may silence this warning and allow it anyway with '--trusted-host pypi.douban.com'.

那么你应该尝试这个命令:

pip install [whatyouwant] -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

这样就可以完美的解决这个问题啦!

评论 42
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值