我正在尝试使用 pip
安装 Python 库,出现 SSL 错误:
~/projects/base pre-master± pip install xdict
Collecting xdict
Could not fetch URL https://pypi.python.org/simple/xdict/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) - skipping
Could not find a version that satisfies the requirement xdict (from versions: )
No matching distribution found for xdict
pip 版本:pip 9.0.1
如何解决这个错误?
最佳答案
升级pip如下:
curl https://bootstrap.pypa.io/get-pip.py | python
注意:如果不在虚拟环境中,您可能需要使用上述sudo python
。
(请注意,使用 pip
升级 pip
即 pip install --upgrade pip
也不会正确升级它。这只是一只鸡- and-egg 问题。除非使用 TLS >= 1.2,否则 pip
将不起作用。)
如 this detailed answer 中所述,这是由于最近 TLS 弃用了 pip。 Python.org 网站有 stopped support适用于 TLS 版本 1.0 和 1.1。
从 Python 状态页面:
Completed - The rolling brownouts are finished, and TLSv1.0 and TLSv1.1 have been disabled. Apr 11, 15:37 UTC
对于 PyCharm(虚拟环境)用户:
使用 shell 运行虚拟环境。 (把“./venv/bin/activate”换成你自己的路径)
source ./venv/bin/activate
运行升级
curl https://bootstrap.pypa.io/get-pip.py | python
重启你的 PyCharm 实例,并在 Preference 中检查你的 Python 解释器。
关于python - 无法安装 Python 包 [SSL : TLSV1_ALERT_PROTOCOL_VERSION],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49768770/