`pip` 安装 Python 包时,提高下载速度的几个常用的国内 `pip` 镜像

在中国使用 pip 安装 Python 包时,为了提高下载速度,可以使用国内的镜像站点。以下是几个常用的国内 pip 镜像地址:

  1. 清华大学

    • 地址:https://pypi.tuna.tsinghua.edu.cn/simple/
  2. 阿里云

    • 地址:https://mirrors.aliyun.com/pypi/simple/
  3. 中国科学技术大学

    • 地址:https://pypi.mirrors.ustc.edu.cn/simple/
  4. 豆瓣

    • 地址:http://pypi.douban.com/simple/
  5. 华中科技大学

    • 地址:https://pypi.hustunique.com/
  6. 腾讯

    • 地址:https://mirrors.cloud.tencent.com/pypi/simple/
  7. 华为

    • 地址:https://repo.huaweicloud.com/repository/pypi/simple/
  8. 百度

    • 地址:https://mirror.baidu.com/pypi/simple/
  9. 搜狐

    • 地址:http://mirrors.sohu.com/Python/

如何临时使用国内镜像源

如果你想临时使用某个国内镜像源来安装一个包,可以在 pip install 命令后面加上 -i 参数和镜像源地址,例如:

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

如何永久更换国内镜像源

如果你希望永久地更换 pip 的默认镜像源,可以通过编辑或创建 pip 的配置文件来实现。对于 Linux 和 macOS 用户,这个文件通常位于 ~/.pip/pip.conf;对于 Windows 用户,这个文件位于 %HOMEPATH%\pip\pip.ini

以阿里云镜像为例,你可以将以下内容添加到相应的配置文件中:

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

或者,你也可以通过命令行直接设置:

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

这样做后,每次使用 pip 安装包时,都会自动从指定的镜像源下载。

猜你喜欢

转载自blog.csdn.net/weixin_40986713/article/details/143363743