如何在python中配置pip源

在 Python 中配置阿里云镜像源(阿里云 PyPI 镜像)可以显著提升国内下载速度。以下是详细配置方法:

临时使用阿里云


在安装包时直接指定阿里云镜像:

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

永久配置阿里云源


方法一:修改 pip 配置文件(推荐)


Windows 系统:
  1. 打开文件资源管理器,输入路径:

  %APPDATA%\pip\

2. 创建或编辑 `pip.ini` 文件,添加:

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

Linux/macOS 系统:
  1. 创建或编辑配置文件:

     mkdir -p ~/.pip && nano ~/.pip/pip.conf


  2. 写入以下内容:

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

方法二:命令行一键配置

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

验证配置是否生效

pip config list


输出应包含:

global.index-url='https://mirrors.aliyun.com/pypi/simple'
global.trusted-host='mirrors.aliyun.com'

恢复默认源

pip config unset global.index-url
pip config unset global.trusted-host

阿里云镜像源地址

HTTP:http://mirrors.aliyun.com/pypi/simple
HTTPS:https://mirrors.aliyun.com/pypi/simple
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值