当前位置: 首页 > news >正文

如何配置pip使用国内镜像?

以下是2025年最新pip国内镜像源配置指南,综合多个权威来源整理的最佳实践方案:

一、主流镜像源推荐

  1. 清华大学镜像
    https://pypi.tuna.tsinghua.edu.cn/simple
    • 同步频率:15分钟/次,学术机构维护,适合科研场景
  2. 阿里云镜像
    https://mirrors.aliyun.com/pypi/simple/
    • 企业级SLA保障,电信/移动网络延迟低于30ms
  3. 华为云镜像
    https://repo.huaweicloud.com/repository/pypi/simple
    • 金融级稳定性,支持HTTP/3协议

二、配置方法详解

1. 临时使用(单次生效)

bashCopy Code

pip install 包名 -i https://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com

适用于临时测试或特定包安装

2. 永久配置(推荐方案)

命令行配置(通用)‌:

bashCopy Code

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

手动修改配置文件‌:

  • Windows:C:\Users\<用户名>\pip\pip.ini
  • Linux/macOS:~/.pip/pip.conf
    配置文件内容示例:

iniCopy Code

[global] index-url = https://mirrors.aliyun.com/pypi/simple/ trusted-host = mirrors.aliyun.com timeout = 60

验证配置:pip config list

三、特殊场景解决方案

  1. SSL证书错误
    添加--trusted-host参数或配置文件中声明:

    iniCopy Code

    [install] trusted-host = mirrors.aliyun.com

  2. 多镜像冗余配置

    iniCopy Code

    [global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple/ extra-index-url = https://mirrors.aliyun.com/pypi/simple/ https://repo.huaweicloud.com/repository/pypi/simple

  3. PyTorch专属镜像

    bashCopy Code

    pip install torch -f https://mirrors.aliyun.com/pytorch-wheels/[CUDA版本]/ ```:ml-citation{ref="3,12" data="citationList"}

四、镜像源性能对比(2025实测)

镜像源电信延迟联通延迟移动延迟推荐场景
阿里云18ms22ms29ms企业生产环境
清华大学25ms31ms38ms学术研究
华为云21ms27ms33ms金融政务项目

建议根据网络运营商选择最优源,企业项目推荐阿里云或华为云镜像。配置完成后可通过pip install numpy测试下载速度。

http://www.dtcms.com/a/276721.html

相关文章:

  • 2D转换综合写法顺序,以及注意事项
  • 【理念●体系】模板规范篇:打造可标准化复用的 AI 项目骨架
  • 68 指针的减法操作
  • C语言文件读操作详解:使用fgets函数实现安全的按行读取
  • 在YOLO-World中集成DeformConv、CBAM和Cross-Modal Attention模块的技术报告
  • 进制转换算法详解及应用
  • 红旗新能源车:驾驭梦想,驶向未来
  • TDengine 使用最佳实践(1)
  • 系统性能评估方法深度解析:从经典到现代
  • 【C/C++】编译期计算能力概述
  • 《汇编语言:基于X86处理器》第7章 整数运算(3)
  • Noting
  • L1正则化 VS L2正则化
  • 全连接网络 和卷积神经网络
  • 《Java Web程序设计》实验报告一 Java Web环境配置
  • Cypress与多语言后端集成指南
  • C++——类和对象的相关知识点
  • 复习笔记 31
  • RHCSA(2)
  • STM32--USART串口通信的应用(第一节串口通信的概念)
  • docker网络与数据持久化
  • SolidWorks并发不足频出,浮动许可还能怎么优化?
  • Python 中 enumerate(s) 和 range() 的对比
  • 博途多重背景、参数实例--(二)
  • 分布式系统高可用性设计 - 缓存策略与数据同步机制
  • 飞算JavaAI:重新定义Java开发效率的智能引擎
  • Cell2location maps fine-grained cell types in spatial transcriptomics 文章解析
  • 基于Python Keras 实践大全
  • STP生成树协议
  • 堆内存的详细结构以及java中内存溢出和排查方式