pip安装超时问题
默认情况下 pip 使用的是国外的镜像,在下载的时候速度非常慢,本文介绍2中处理方法
一)
1、设置超时时间
pip --default-timeout=1000 install -U 模块名
例如
pip --default-timeout=1000 install -U matplotlib
来下载matplotlib,让它的延迟检测时间变长。
2、使用镜像网址来代替
国内清华大学的源:https://pypi.tuna.tsinghua.edu.cn/simple
豆瓣:https://pypi.douban.com/simple
中国科学技术大学 : https://pypi.mirrors.ustc.edu.cn/simple
阿里云:https://mirrors.aliyun.com/pypi/simple/
华为云:https://mirrors.huaweicloud.com/repository/pypi/simple
例如
pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
-i:指定镜像地址
这种只对当前安装对命令有用,如果需要全局修改,则需要修改配置文件。
Linux/Mac os 环境中,配置文件位置在 ~/.pip/pip.conf(如果不存在创建该目录和文件):
打开配置文件 ~/.pip/pip.conf,修改如下(可根据需要设置镜像源):
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host = https://pypi.tuna.tsinghua.edu.cn
查看 镜像地址:
$ pip3 config list global.index-url='https://pypi.tuna.tsinghua.edu.cn/simple' install.trusted-host='https://pypi.tuna.tsinghua.edu.cn'
Windows下,你需要在当前对用户目录下(C:\Users\xx\pip,xx 表示当前使用对用户,比如张三)创建一个 pip.ini在pip.ini文件中输入以下内容:
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host = pypi.tuna.tsinghua.edu.cn
二)
升级pip版本
pip install --upgrade pip -i https://pypi.douban.com/simple
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏