日常使用 Python 安装第三方库,配置国内 PyPI 镜像源可以大幅提升下载速度,下面整理主流可用国内镜像,统一只保留 HTTPS 安全地址,可直接收藏使用。
清华大学 PyPI 镜像
plaintext
https://pypi.tuna.tsinghua.edu.cn/simple/
阿里云 PyPI 镜像
plaintext
https://mirrors.aliyun.com/pypi/simple/
中国科学技术大学 PyPI 镜像
plaintext
https://pypi.mirrors.ustc.edu.cn/simple/
腾讯云 PyPI 镜像
plaintext
https://mirrors.cloud.tencent.com/pypi/simple/
华为云 PyPI 镜像
plaintext
https://repo.huaweicloud.com/repository/pypi/simple/
常用配置用法
1. 临时单次使用
pip install 包名 -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn
2. 设为全局默认镜像(永久生效)
# 设置清华源为默认
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/
pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn
3. 查看当前 pip 镜像配置
pip config list
4. 删除镜像配置
pip config unset global.index-url
pip config unset global.trusted-host