python - 无法安装 Python 包 [SSL : TLSV1_ALERT_PROTOCOL

我正在尝试使用 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 升级 pippip 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(虚拟环境)用户:

  1. 使用 shell 运行虚拟环境。 (把“./venv/bin/activate”换成你自己的路径)

    source ./venv/bin/activate
    
  2. 运行升级

    curl https://bootstrap.pypa.io/get-pip.py | python
    
  3. 重启你的 PyCharm 实例,并在 Preference 中检查你的 Python 解释器。

关于python - 无法安装 Python 包 [SSL : TLSV1_ALERT_PROTOCOL_VERSION],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49768770/

相关文章:

python - 将字符串转换为 Python 类对象?

c - unix域套接字VS命名管道?

python - 如何从字符串中删除所有空格

python - 将 Pandas 函数应用于列以创建多个新列?

linux - 设置 Vim 背景颜色

python - 通过urllib和python下载图片

linux - ~/.ssh/config 文件中的 SSH 端口转发?

python - 为什么 PyPy 没有包含在标准 Python 中?

linux - tar.gz 和 tgz 是一回事吗?

linux - 从 linux shell 脚本发送邮件