pip安装报403错误:Could not fetch URL,Client Error: TLSv1.2+ is required for url

时间:2022-06-01 18:45:04

最近在Mac上使用pip 9.0.1安装任何python软件包时会报类似的错误:

Status code 403 not in [200, 203, 300, 301]
Could not fetch URL https://pypi.python.org/simple/<package>/: 403 Client Error: TLSv1.2+ is required for url: https://pypi.python.org/simple/<package>/ - skipping
Could not find a version that satisfies the requirement <package> (from versions: )
Cleaning up...
No matching distribution found for <package>

这是因为Python.org网站停止了对TLS1.0和1.1的支持。 如错误信息的提示,下载https://pypi.python.org/simple/<package>需要使用TLSv1.2+。

对于macOS < 10.13,pip需要升级到9.0.3。pip 9.0.3支持TLSv1.2。升级脚本如下:

curl https://bootstrap.pypa.io/get-pip.py | python

注意:不能使用pip直接升级pip,以下命令是升级不了的:

pip install --upgrade pip

升级pip后,建议也升级setuptools:

pip install --upgrade setuptools