健康一贴灵,专注医药行业管理信息化

设置pip全局镜像源(国内加速)

 

方法一:通过命令行设置(推荐)

Windows/Linux/macOS通用
# 设置全局镜像源(以清华大学源为例)
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn

# 如果需要设置额外索引(对某些特殊包)
pip config set global.extra-index-url https://mirrors.aliyun.com/pypi/simple/

方法二:手动编辑配置文件

Windows系统
  1. 打开资源管理器,在地址栏输入:%APPDATA%
  2. 进入该目录,找到或创建pip文件夹
  3. pip文件夹中创建或编辑pip.ini文件
  4. 添加以下内容:
    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple
    trusted-host = pypi.tuna.tsinghua.edu.cn
    timeout = 6000

    设置pip全局镜像源(国内加速)

    方法一:通过命令行设置(推荐)

    Windows/Linux/macOS通用
     
    # 设置全局镜像源(以清华大学源为例)
    pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
    pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn
    
    # 如果需要设置额外索引(对某些特殊包)
    pip config set global.extra-index-url https://mirrors.aliyun.com/pypi/simple/
     
     

    方法二:手动编辑配置文件

    Windows系统
    1. 打开资源管理器,在地址栏输入:%APPDATA%
    2. 进入该目录,找到或创建pip文件夹
    3. pip文件夹中创建或编辑pip.ini文件
    4. 添加以下内容:
     
    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple
    trusted-host = pypi.tuna.tsinghua.edu.cn
    timeout = 6000
     
     
    Linux/macOS系统
    1. 创建或编辑配置文件:
     
    mkdir -p ~/.pip
    vim ~/.pip/pip.conf
     
     
    1. 添加以下内容:
     
    [global]
    index-url = https://pypi.tuna.tsinghua.edu.cn/simple
    trusted-host = pypi.tuna.tsinghua.edu.cn
    timeout = 6000
     
     

    国内常用镜像源列表

     
    # 清华大学
    https://pypi.tuna.tsinghua.edu.cn/simple
    
    # 阿里云
    https://mirrors.aliyun.com/pypi/simple/
    
    # 腾讯云
    https://mirrors.cloud.tencent.com/pypi/simple
    
    # 华为云
    https://repo.huaweicloud.com/repository/pypi/simple
    
    # 豆瓣
    https://pypi.douban.com/simple/
    
    # 中科大
    https://pypi.mirrors.ustc.edu.cn/simple/


    验证设置是否生效
    # 查看当前配置
    pip config list
    
    # 或查看具体配置项
    pip config get global.index-url

     

posted @ 2026-04-27 15:46  一贴灵  阅读(107)  评论(0)    收藏  举报
学以致用,效率第一