简体   繁体   English

无法安装 Python 包 [SSL: TLSV1_ALERT_PROTOCOL_VERSION]

[英]Not able to install Python packages [SSL: TLSV1_ALERT_PROTOCOL_VERSION]

I am trying to install a Python library using pip , getting an SSL error:我正在尝试使用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 version: pip 9.0.1 pip 版本:pip 9.0.1

How do I fix this error?我该如何解决这个错误?

Upgrade pip as follows:升级pip如下:

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

Note: You may need to use sudo python above if not in a virtual environment.注意:如果不是在虚拟环境中,您可能需要使用上面的sudo python

(Note that upgrading pip using pip ie pip install --upgrade pip will also not upgrade it correctly. It's just a chicken-and-egg issue. pip won't work unless using TLS >= 1.2.) (请注意,使用pip升级pip ie pip install --upgrade pip也不会正确升级它。这只是一个先有鸡还是先有蛋的问题。除非使用 TLS >= 1.2,否则pip将无法工作。)

As mentioned in this detailed answer , this is due to the recent TLS deprecation for pip.如此详细答案中所述,这是由于最近 TLS 弃用了 pip。 Python.org sites have stopped support for TLS versions 1.0 and 1.1. Python.org 站点已停止支持TLS 1.0 和 1.1 版。

From the Python status page:从 Python 状态页面:

Completed - The rolling brownouts are finished, and TLSv1.0 and TLSv1.1 have been disabled.已完成- 滚动停电已完成,TLSv1.0 和 TLSv1.1 已禁用。 Apr 11, 15:37 UTC世界标准时间 4 月 11 日 15:37


For PyCharm (virtualenv) users:对于 PyCharm (virtualenv) 用户:

  1. Run virtual environment with shell.使用 shell 运行虚拟环境。 (replace "./venv/bin/activate" to your own path) (将“./venv/bin/activate”替换为您自己的路径)

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

    curl https://bootstrap.pypa.io/get-pip.py | python
  3. Restart your PyCharm instance, and check your Python interpreter in Preference .重新启动您的 PyCharm 实例,并在Preference 中检查您的 Python 解释器。

But if the curl command itself fails with error, or "tlsv1 alert protocol version" persists even after upgrading pip , it means your operating system's underlying OpenSSL library version< 1.0.1 or Python version< 2.7.9 (or < 3.4 in Python 3) do not support the newer TLS 1.2 protocol that pip needs to connect to PyPI since about a year ago .但是,如果curl命令本身失败并出现错误,或者即使升级pip“tlsv1 警报协议版本”仍然存在,则意味着您的操作系统的底层 OpenSSL 库版本< 1.0.1或 Python 版本< 2.7.9 (或 Python 3 中的 < 3.4 ) 大约一年前,不支持pip需要连接到 PyPI 的较新的 TLS 1.2 协议。 You can easily check it in Python interpreter:您可以在 Python 解释器中轻松检查它:

>>> import ssl
>>> ssl.OPENSSL_VERSION
'OpenSSL 0.9.8o 01 Jun 2010'
>>> ssl.PROTOCOL_TLSv1_2
 AttributeError: 'module' object has no attribute 'PROTOCOL_TLSv1_2'

The AttributeError (instead of expected '5') means your Python stdlib ssl module, compiled against old openssl lib, is lacking support for the TLSv1.2 protocol (even if the openssl library can or could be updated later). AttributeError (而不是预期的“5”)意味着您的 Python stdlib ssl模块(针对旧的 openssl 库编译)缺乏对 TLSv1.2 协议的支持(即使 openssl 库可以或可以稍后更新)。

Fortunately, it can be solved without upgrading Python (and the whole system), by manually installing extra Python packages -- the detailed step-by-step guide is available here on Stackoverflow .幸运的是,它可以在不升级 Python (和整个系统)的情况下解决,通过手动安装额外的 Python 包 - Stackoverflow 上提供了详细的分步指南。

Note, curl and pip and wget all depend on the same OpenSSL lib for establishing SSL connections (use $ openssl version command).注意, curlpip以及wget都依赖于相同的 OpenSSL 库来建立 SSL 连接(使用$ openssl version命令)。 libcurl supports TLS 1.2 since curl version 7.34 , but older curl versions should be able to connect if you had OpenSSL version 1.0.2 (or later). libcurl 从 curl 版本7.34开始支持 TLS 1.2,但如果您有 OpenSSL 版本 1.0.2(或更高版本),旧的 curl 版本应该能够连接。


PS聚苯乙烯
For Python 3 , please use python3 and pip3 everywhere (unless you are in a venv/virtualenv), including the curl command from above :对于Python 3 ,请在任何地方使用python3pip3 (除非您在 venv/virtualenv 中),包括上面curl命令:
$ curl https://bootstrap.pypa.io/get-pip.py | python3 --user

Following @Anupam's answer on OS X resulted in the following error for me, regardless of permissions I ran it with:遵循@Anupam 在 OS X 上的回答导致我出现以下错误,无论我运行它的权限如何:

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: ...由于环境错误,无法安装软件包:[Errno 13] 权限被拒绝:...

What eventually worked was to download a newer pip package (9.0.3) from PyPI directly from my browser - https://pypi.org/simple/pip/ , extract the contents, and then pip install the package locally:最终有效的是直接从我的浏览器 - https://pypi.org/simple/pip/从 PyPI 下载更新的 pip 包(9.0.3),提取内容,然后在本地 pip 安装包:

pip install ./pip-9.0.3/

This fixed my [SSL: TLSV1_ALERT_PROTOCOL_VERSION] errors.这修复了我的[SSL: TLSV1_ALERT_PROTOCOL_VERSION]错误。

@Anupam 's solution worked for me. @Anupam的解决方案对我有用 However, I had to use sudo and specify the exact location of my virtual Python environment:但是,我必须使用sudo并指定我的虚拟 Python 环境的确切位置:

curl https://bootstrap.pypa.io/get-pip.py | sudo /Users/{your user name}/{path to python}/bin/python

To upgrade the local version I used a slight variant:为了升级本地版本,我使用了一个轻微的变体:

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

This problem arises if you keep your pip and packages under your home directory as described in this gist .如果您按照本要点中的描述将 pip 和包保存在主目录下,则会出现此问题。

Check your TLS version:检查您的 TLS 版本:

python2 -c "import urllib2,json; print(json.loads(urllib2.urlopen('https://www.howsmyssl.com/a/check').read())['tls_version'])"

If your TLS version is less than 1.2 you have to upgrade it since the PyPI repository is on a brownout period of deprecating early TLS.如果您的 TLS 版本低于 1.2,您必须升级它,因为 PyPI 存储库正处于弃用早期 TLS 的限制期。

Source - Time To Upgrade Your Python: TLS v1.2 Will Soon Be Mandatory来源 - 是时候升级您的 Python:TLS v1.2 将很快成为强制性要求

You can upgrade the TLS version using the following command:您可以使用以下命令升级 TLS 版本:

sudo apt-get update && sudo apt-get install openssl libssl-dev

This should fix your problem.这应该可以解决您的问题。 Good luck!祝你好运!

EDIT: You can download packages using your own private python package repository regardless of TLS version.编辑:无论 TLS 版本如何,您都可以使用自己的私有 python 包存储库下载包。 Private Python Package Repository 私有 Python 包存储库

The following solution worked for me:以下解决方案对我有用:

brew install python2

It also upgraded pip to version 1.10.1它还将pip升级到 1.10.1 版

For Python2 WIN10 Users:对于 Python2 WIN10 用户:

1.Uninstall python thoroughly ,include all folders. 1.彻底卸载python,包括所有文件夹。

2.Fetch and install the lastest python-2.7.msi (ver 2.7.15) 2.获取并安装最新的python-2.7.msi (ver 2.7.15)

3.After step 2,you may find pip had been installed too. 3.在第2步之后,你可能会发现pip也已经安装好了。

4.Now ,if your system'env haven't been changed,you can use pip to install packages now.The "tlsv1 alert protocol version" will not appear. 4.现在,如果你的系统环境没有改变,你现在可以使用pip安装包。“tlsv1警报协议版本”不会出现。

This worked for me.这对我有用。 Add sudo before python在python之前添加sudo

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

I tried all existing fixes and not working for me我尝试了所有现有的修复程序,但对我不起作用

I re-install python 2.7 (will also install pip) by downloading .pkg at https://www.python.org/downloads/mac-osx/我通过在https://www.python.org/downloads/mac-osx/下载 .pkg 重新安装 python 2.7(也将安装 pip)

works for me after installation downloaded pkg安装下载 pkg 后对我有用

I ran into this problem as well.我也遇到了这个问题。 The underlying problem is that the ssl library in Python 2.7 versions < 2.7.9 is no longer compatible with the pip mechanism.底层问题是Python 2.7 版本< 2.7.9 中的ssl 库不再兼容pip 机制。

If you are running on Windows, and you (like us) can't easily upgrade from an incompatible version of 2.7, FWIW, I found that if you copy the following files from another install of the latest version of Python (eg Python 2.7.15) on another machine to your installation:如果您在 Windows 上运行,并且您(像我们一样)无法从不兼容的 2.7 版本 FWIW 轻松升级,我发现如果您从另一个安装的最新 Python 版本(例如 Python 2.7. 15)在另一台机器上安装:

    Lib\ssl.py
    libs\_ssl.lib
    DLLs\_ssl.dll

it will effectively "upgrade" your SSL layer to one which is supported;它将有效地将您的 SSL 层“升级”到受支持的层; we were then be able to use pip again, even to upgrade pip.然后我们就可以再次使用 pip,甚至升级 pip。

For all the python3 and pip3 users out there:对于所有的python3pip3用户:

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

and then assume you want to install pandas然后假设您要安装熊猫

pip3 install pandas --user

The answers of installing pip via:通过以下方式安装 pip 的答案:

  1. curl https://bootstrap.pypa.io/get-pip.py |sudo python or curl https://bootstrap.pypa.io/get-pip.py |sudo python
  2. curl https://bootstrap.pypa.io/get-pip.py | python

did not work for me as I kept on getting the error:对我不起作用,因为我不断收到错误消息:

Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping
ERROR: Could not find a version that satisfies the requirement pip (from versions: none)
ERROR: No matching distribution found for pip

I had to install pip manually via:我必须通过以下方式手动安装pip

  1. Go the pip distribution websitepip分发网站
  2. Download the tar.gz version下载tar.gz版本
  3. Unpack the file locally and cd into the directory在本地解压文件并cd到目录中
  4. run python setup.py install运行python setup.py install

This worked for me, I installed latest version of pip and then installed the library ( ciscoconfparse ).这对我有用,我安装了最新版本的 pip,然后安装了库( ciscoconfparse )。

Upgrading pip:升级点:

curl https://bootstrap.pypa.io/get-pip.py | sudo /Users/{your user name}/{path to python}/bin/python

I also hit this problem on my windows10 and tried all the answers but didn't solve my problem.我也在我的 windows10 上遇到了这个问题并尝试了所有的答案,但没有解决我的问题。

C:\\python367\\Scripts>pip install Flask C:\\python367\\Scripts>pip install Flask

Collecting Flask Could not find a version that satisfies the requirement Flask (from versions: ) No matching distribution found for Flask收集 Flask 找不到满足 Flask 要求的版本(来自版本:)找不到 Flask 的匹配发行版

After that, I find the pip configuration file had been modified.之后,我发现pip配置文件被修改了。 So, I set the pip.ini as the original default configuration, re-run the pip command and it works for me!因此,我将pip.ini设置为原始默认配置,重新运行 pip 命令,它对我pip.ini

In summary of the solution of mine:总结一下我的解决方案:

  1. Check the pip.ini (usually under the path C:\\ProgramData\\pip ) had been modified;检查pip.ini(一般在C:\\ProgramData\\pip路径下)是否被修改;

  2. If yes in step1, try to reset it to a default configuration.如果在步骤 1 中是,请尝试将其重置为默认配置。

myenv:我的环境:

python 2.7.14蟒蛇 2.7.14

pip 9.0.1点子 9.0.1

mac osx 10.9.4 mac osx 10.9.4


mysolution:我的解决方案:

  1. download get-pip.py manually from https://packaging.python.org/tutorials/installing-packages/https://packaging.python.org/tutorials/installing-packages/手动下载get-pip.py

  2. run python get-pip.py运行python get-pip.py


refs:参考:

https://github.com/pypa/warehouse/issues/3293#issuecomment-378468534 https://github.com/pypa/warehouse/issues/3293#issuecomment-378468534

https://packaging.python.org/tutorials/installing-packages/ https://packaging.python.org/tutorials/installing-packages/

Securely Download get-pip.py [1]安全下载 get-pip.py [1]

Run python get-pip.py.运行 python get-pip.py。 [2] This will install or upgrade pip. [2] 这将安装或升级 pip。 Additionally, it will install setuptools and wheel if they're not installed already.此外,如果尚未安装 setuptools 和 wheel,它将安装它们。

Ensure pip, setuptools, and wheel are up to date确保 pip、setuptools 和 wheel 是最新的

While pip alone is sufficient to install from pre-built binary archives, up to date copies of the setuptools and wheel projects are useful to ensure you can also install from source archives:虽然 pip 足以从预先构建的二进制档案安装,但 setuptools 和 wheel 项目的最新副本对于确保您也可以从源档案安装:

python -m pip install --upgrade pip setuptools wheel

Or simply the required library just isn't in the repo.或者只是所需的库不在回购中。 I'm Python newbie and all advices about upgrading pip finally shown as misleading.我是 Python 新手,所有关于升级 pip 的建议最终都显示为误导。 I had just to look into https://pypi.org/ , finding the library (airflow in my case) stopped at some old version, after which it was renamed.我只需要查看https://pypi.org/ ,发现库(在我的情况下是气流)停在某个旧版本上,之后它被重命名。 Yes, also that silly solution is also possible :-).是的,那个愚蠢的解决方案也是可能的:-)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法安装任何库[SSL:TLSV1_ALERT_PROTOCOL_VERSION] - Not able to install any library [SSL: TLSV1_ALERT_PROTOCOL_VERSION] 升级pip /安装Django-[SSL:TLSV1_ALERT_PROTOCOL_VERSION] - Upgrading pip/installing django - [SSL: TLSV1_ALERT_PROTOCOL_VERSION] 使用pip安装python软件包时出错(TLSV1_ALERT_PROTOCOL_VERSION) - Error installing python package with pip (TLSV1_ALERT_PROTOCOL_VERSION) 仍然无法安装自动登录-TLSV1_ALERT_PROTOCOL_VERSION - still cannot install autologin - TLSV1_ALERT_PROTOCOL_VERSION TLSV1_ALERT_PROTOCOL_VERSION 与 python 请求包 - TLSV1_ALERT_PROTOCOL_VERSION with python requests package requests.exceptions.SSLError:[SSL:TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version(_ssl.c:590) - requests.exceptions.SSLError: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) 无法在 Ubuntu Linux 中使用 pip 安装 Python 包:InsecurePlatformWarning、SSLError、tlsv1 警报协议版本 - Unable to install Python packages using pip in Ubuntu Linux: InsecurePlatformWarning, SSLError, tlsv1 alert protocol version ssl.SSLError:tlsv1 警报协议版本 - ssl.SSLError: tlsv1 alert protocol version Python HTTPS/SSL 错误:1407742E:SSL 例程:SSL23_GET_SERVER_HELLO:tlsv1 警报协议版本 - Python HTTPS/SSL error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version Python - Docker 客户端连接中的 tlsv1 警报协议版本错误 - Python - tlsv1 alert protocol version error in Docker client connection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM