pip配置阿里云、清华和中科大的镜像

pip 配置文件中,默认情况下只能配置一个主镜像源。如果你想配置多个镜像源,可以使用 extra-index-url 选项来指定额外的镜像源。这些额外的镜像源将在主镜像源不可用时作为备选。

配置多个镜像源

你可以编辑 pip 的配置文件,添加多个镜像源。以下是如何在 pip 的配置文件中配置清华大学、阿里云和中国科学技术大学的镜像源。

方法一:通过 pip 配置命令

你可以使用 pip config 命令来设置额外的镜像源:

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config set global.extra-index-url https://mirrors.aliyun.com/pypi/simple
pip config set global.extra-index-url https://pypi.mirrors.ustc.edu.cn/simple
方法二:手动编辑 pip 配置文件
  • Linux 和 MacOS

    编辑或创建文件 ~/.pip/pip.conf,添加以下内容:

    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple
    extra-index-url =
        https://mirrors.aliyun.com/pypi/simple
        https://pypi.mirrors.ustc.edu.cn/simple
    
  • Windows

    编辑或创建文件 %APPDATA%\pip\pip.ini,添加以下内容:

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

示例

以下是一个完整的示例,展示如何在 Linux 系统上配置多个镜像源:

  1. 创建或编辑 ~/.pip/pip.conf 文件:
mkdir -p ~/.pip
nano ~/.pip/pip.conf
  1. 添加以下内容到 pip.conf 文件中:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
extra-index-url =
    https://mirrors.aliyun.com/pypi/simple
    https://pypi.mirrors.ustc.edu.cn/simple
  1. 保存文件并退出编辑器。

通过这种方式,你可以配置多个镜像源,以提高 pip 的包管理效率。如果主镜像源不可用,pip 将会尝试使用额外的镜像源来下载包。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值