PyPi 镜像使用帮助

2020-07-10T09:33:00

我们在使用Python的过程中,难免会遇到使用pip安装软件包特别慢的情况,这主要是因为pip的默认软件源服务器在国外,国内访问比较的慢。幸运的是现在国内有很多的镜像源供我们使用,可以大大提高我们安装软件包的速度。这篇文章主要介绍如何设置并使用 Python 的第三方镜像源。

pypi 镜像使用帮助

手动更新镜像源参考:更新 Python pip 镜像源为阿里云

临时使用第三方镜像

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

注意,simple 不能少, 是 https 而不是 http,使用 http 镜像源时需要追加参数 --trusted-host

设为第三方镜像默认源

升级 pip 到最新的版本 (>=10.0.0) 后进行配置:

pip install pip -U

如果您到 pip 默认源的网络连接较差,临时使用本镜像站来升级 pip:

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

设置为清华大学镜像源

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

设置为华为云镜像源

pip config set global.index-url https://mirrors.huaweicloud.com/repository/pypi/simple

使用 http 镜像源

当系统使用代理时,使用 PIP 安装软件时可能出现 SSLEOFError 错误

HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /pypi/httpx/json (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:997)')))

这种情况下 pip 无法使用代理访问 https 镜像源,这是我们需要使用 http 镜像源,比如阿里云提供的镜像就是支持 http 访问,使用下面命令即可设置镜像源。

# 设置镜像源为阿里云http镜像
pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/
# 设置信任阿里云镜像域名
pip config set install.trusted-host mirrors.aliyun.com

第三方镜像源

豆瓣 https://pypi.doubanio.com/simple/
网易 https://mirrors.163.com/pypi/simple/
阿里云 https://mirrors.aliyun.com/pypi/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
当前页面是本站的「Baidu MIP」版。发表评论请点击:完整版 »