好的,我来帮你整理 Python 国内镜像源 的使用方法和常用源列表,方便在国内加速下载 Python 包。


🔹 为什么使用国内镜像源?

  • Python 官方 PyPI 源:https://pypi.org/simple
  • 在国内访问可能 速度慢或超时
  • 国内镜像源提供 高速、稳定下载

🔹 常用国内镜像源

镜像源URL
阿里云https://mirrors.aliyun.com/pypi/simple/
清华大学https://pypi.tuna.tsinghua.edu.cn/simple/
中国科技大学https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣https://pypi.doubanio.com/simple/
华中理工大学https://pypi.hustunique.com/
北京理工大学https://mirror.bit.edu.cn/pypi/simple/

🔹 临时使用镜像源

在安装包时指定 -i 参数:

pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple

  • 仅对当前命令有效

🔹 永久使用镜像源

方法 1:修改 pip 配置文件

Linux / Mac

编辑或创建 ~/.pip/pip.conf

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

Windows

编辑或创建 %APPDATA%\pip\pip.ini

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

  • 之后所有 pip install 默认使用国内镜像

🔹 升级 pip 时使用镜像源

python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple


🔹 常用技巧

  1. 查看当前源:
pip config get global.index-url

  1. 清理缓存:
pip cache purge

  1. 指定多个源(备用源):
pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple --extra-index-url https://mirrors.aliyun.com/pypi/simple/


✅ 总结

  • 国内镜像源可以 加速 Python 包下载
  • 临时使用 -i 参数
  • 永久使用修改 pip.conf 或 pip.ini
  • 常用镜像推荐:清华、阿里、USTC、豆瓣