问题:无法安装Python软件包[SSL:TLSV1_ALERT_PROTOCOL_VERSION]
我正在尝试使用安装Python库pip
,并收到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
点子版本:点子9.0.1
如何解决此错误?
I am trying to install a Python library using pip
, getting an SSL error:
~/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
How do I fix this error?
回答 0
升级点如下:
curl https://bootstrap.pypa.io/get-pip.py | python
注意:sudo python
如果不在虚拟环境中,则可能需要使用以上内容。
(请注意,pip
使用pip
ie进行pip install --upgrade pip
升级也不会正确升级。这只是一个鸡与蛋的问题。pip
除非使用TLS> = 1.2,否则它将无法正常工作。)
如本详细答案所述,这是由于最近对pip的TLS弃用。Python.org网站已停止支持 TLS版本1.0和1.1。
从Python状态页面:
已完成 -滚动式电源不足已完成,并且TLSv1.0和TLSv1.1已被禁用。世界标准时间4月11日15:37
对于PyCharm(virtualenv)用户:
使用Shell运行虚拟环境。(将“ ./venv/bin/activate”替换为您自己的路径)
source ./venv/bin/activate
运行升级
curl https://bootstrap.pypa.io/get-pip.py | python
重新启动您的PyCharm实例,然后在Preference中检查您的Python解释器。
Upgrade pip as follows:
curl https://bootstrap.pypa.io/get-pip.py | python
Note: You may need to use sudo python
above if not in a virtual environment.
(Note that upgrading pip
using pip
i.e 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.)
As mentioned in this detailed answer, this is due to the recent TLS deprecation for pip. Python.org sites have stopped support for TLS versions 1.0 and 1.1.
From the Python status page:
Completed – The rolling brownouts are finished, and TLSv1.0 and TLSv1.1 have been disabled. Apr 11, 15:37 UTC
For PyCharm (virtualenv) users:
Run virtual environment with shell. (replace “./venv/bin/activate” to your own path)
source ./venv/bin/activate
Run upgrade
curl https://bootstrap.pypa.io/get-pip.py | python
Restart your PyCharm instance, and check your Python interpreter in Preference.
回答 1
但是,如果curl
命令本身因错误而失败,或者即使升级后“ tlsv1警报协议版本”仍然存在pip
,则表示操作系统的基础OpenSSL库版本< 1.0.1
或Python版本< 2.7.9
(或3.4
Python 3中的< )不支持较新的TLS 1.2协议这pip
需要连接到PyPI中,因为大约一年前。您可以在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'
的AttributeError
(而不是预期的“5”)是指你的Python STDLIB ssl
模块,对旧的OpenSSL的lib编译,缺乏对TLSv1.2工作协议(即使OpenSSL库可以或可以在以后更新)的支持。
幸运的是,无需手动升级额外的Python软件包即可解决此问题,而无需升级Python(以及整个系统),详细的逐步指南位于Stackoverflow上。
注意,curl
并pip
和wget
所有依赖于相同的OpenSSL lib中建立SSL连接(使用$ openssl version
命令)。从curl版本7.34开始,libcurl支持TLS 1.2 ,但是如果您具有OpenSSL版本1.0.2(或更高版本),则较旧的curl版本应该能够连接。
PS
对于Python 3中,请使用python3
和pip3
无处不在(除非你是在一个VENV / virtualenv中),包括curl
从命令上面:
$ curl https://bootstrap.pypa.io/get-pip.py | python3 --user
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. You can easily check it in Python interpreter:
>>> 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).
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.
Note, curl
and pip
and wget
all depend on the same OpenSSL lib for establishing SSL connections (use $ openssl version
command). 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).
P.S.
For Python 3, please use python3
and pip3
everywhere (unless you are in a venv/virtualenv), including the curl
command from above:
$ curl https://bootstrap.pypa.io/get-pip.py | python3 --user
回答 2
在OS X上遵循@Anupam的回答后,无论我使用哪种权限运行,都会导致以下错误:
由于环境错误而无法安装软件包:[Errno 13]权限被拒绝:…
最终什么工作是直接从我的浏览器下载一封来自PyPI一个较新的PIP封装(9.0.3) – https://pypi.org/simple/pip/,提取内容,然后PIP本地安装包:
pip install ./pip-9.0.3/
这解决了我的[SSL: TLSV1_ALERT_PROTOCOL_VERSION]
错误。
Following @Anupam’s answer on OS X resulted in the following error for me, regardless of permissions I ran it with:
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: …
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:
pip install ./pip-9.0.3/
This fixed my [SSL: TLSV1_ALERT_PROTOCOL_VERSION]
errors.
回答 3
@Anupam的解决方案对我有用。但是,我必须使用sudo
并指定虚拟Python环境的确切位置:
curl https://bootstrap.pypa.io/get-pip.py | sudo /Users/{your user name}/{path to python}/bin/python
@Anupam‘s solution worked for me. However, I had to use sudo
and specify the exact location of my virtual Python environment:
curl https://bootstrap.pypa.io/get-pip.py | sudo /Users/{your user name}/{path to python}/bin/python
回答 4
为了升级本地版本,我使用了一个轻微的变体:
curl https://bootstrap.pypa.io/get-pip.py | python - --user
如果您按照本要点所述将pip和程序包放在主目录下,则会出现此问题。
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.
回答 5
以下解决方案为我工作:
brew install python2
它还升级pip
到版本1.10.1
The following solution worked for me:
brew install python2
It also upgraded pip
to version 1.10.1
回答 6
检查您的TLS版本:
python2 -c "import urllib2,json; print(json.loads(urllib2.urlopen('https://www.howsmyssl.com/a/check').read())['tls_version'])"
如果您的TLS版本低于1.2,则您必须对其进行升级,因为PyPI存储库正处于弃用早期TLS的限制期。
来源- 升级Python的时间:TLS v1.2很快将成为必需
您可以使用以下命令升级TLS版本:
sudo apt-get update && sudo apt-get install openssl libssl-dev
这应该可以解决您的问题。祝好运!
编辑:您可以使用自己的专用python软件包存储库下载软件包,而不管TLS版本如何。 专用Python软件包存储库
Check your TLS version:
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.
Source – Time To Upgrade Your Python: TLS v1.2 Will Soon Be Mandatory
You can upgrade the TLS version using the following command:
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. Private Python Package Repository
回答 7
这对我有用。在python之前添加sudo
curl https://bootstrap.pypa.io/get-pip.py |sudo python
This worked for me. Add sudo before python
curl https://bootstrap.pypa.io/get-pip.py |sudo python
回答 8
对于Python2 WIN10用户:
1.彻底卸载python,包括所有文件夹。
2.获取并安装最新的python-2.7.msi(版本2.7.15)
3.步骤2之后,您可能还会发现pip也已安装。
4.现在,如果尚未更改系统的环境,则可以立即使用pip安装软件包。“ tlsv1警报协议版本”将不会出现。
For Python2 WIN10 Users:
1.Uninstall python thoroughly ,include all folders.
2.Fetch and install the lastest python-2.7.msi (ver 2.7.15)
3.After step 2,you may find pip had been installed too.
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.
回答 9
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/
works for me after installation downloaded pkg
回答 10
我也遇到了这个问题。潜在的问题是Python 2.7版本<2.7.9中的ssl库不再与pip机制兼容。
如果您在Windows上运行,并且您(像我们一样)无法轻松地从2.7的不兼容版本FWIW升级,我发现如果您从另一个最新版本的Python(例如Python 2.7)的安装中复制以下文件。 15)在另一台机器上进行安装:
Lib\ssl.py
libs\_ssl.lib
DLLs\_ssl.dll
它将有效地将您的SSL层“升级”到受支持的层;这样我们就可以再次使用pip,甚至可以升级pip。
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.
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 (e.g. Python 2.7.15) on another machine to your installation:
Lib\ssl.py
libs\_ssl.lib
DLLs\_ssl.dll
it will effectively “upgrade” your SSL layer to one which is supported; we were then be able to use pip again, even to upgrade pip.
回答 11
这对我有用,我安装了最新版本的pip,然后安装了库(ciscoconfparse)。
升级点数:
curl https://bootstrap.pypa.io/get-pip.py | sudo /Users/{your user name}/{path to python}/bin/python
This worked for me, I installed latest version of pip and then installed the library (ciscoconfparse).
Upgrading pip:
curl https://bootstrap.pypa.io/get-pip.py | sudo /Users/{your user name}/{path to python}/bin/python
回答 12
回答 13
我也在Windows10上遇到了这个问题,并尝试了所有答案,但没有解决我的问题。
C:\ python367 \ Scripts> pip安装Flask
收集Flask找不到满足Flask要求的版本(来自版本:)找不到Flask的匹配发行版
之后,我发现pip配置文件已被修改。因此,我将设置pip.ini
为原始默认配置,重新运行pip命令,它对我有用!
总结我的解决方案:
检查pip.ini(通常在path下C:\ProgramData\pip
)是否已被修改;
如果在步骤1中为是,请尝试将其重置为默认配置。
I also hit this problem on my windows10 and tried all the answers but didn’t solve my problem.
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
After that, I find the pip configuration file had been modified. So, I set the pip.ini
as the original default configuration, re-run the pip command and it works for me!
In summary of the solution of mine:
Check the pip.ini (usually under the path C:\ProgramData\pip
) had been modified;
If yes in step1, try to reset it to a default configuration.
回答 14
或者只是所需的库不在存储库中。我是Python新手,关于升级pip的所有建议最终都被误导了。我只需要查看https://pypi.org/,发现该库(在我的情况下为气流)停在某个旧版本上,然后将其重命名。是的,愚蠢的解决方案也是可能的:-)。
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. 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. Yes, also that silly solution is also possible :-).
回答 15
对于所有python3
和pip3
用户:
curl https://bootstrap.pypa.io/get-pip.py | sudo python3
然后假设您要安装熊猫
pip3 install pandas --user
For all the python3
and pip3
users out there:
curl https://bootstrap.pypa.io/get-pip.py | sudo python3
and then assume you want to install pandas
pip3 install pandas --user
回答 16
通过以下方式安装pip的答案:
curl https://bootstrap.pypa.io/get-pip.py |sudo python
要么 curl https://bootstrap.pypa.io/get-pip.py | python
由于我不断收到错误,因此对我不起作用:
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
我必须pip
通过以下方式手动安装:
- 前往
pip
发行网站 - 下载
tar.gz
版本 - 将文件解压缩到本地并
cd
进入目录 - 跑
python setup.py install
The answers of installing pip via:
curl https://bootstrap.pypa.io/get-pip.py |sudo python
or 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:
- Go the
pip
distribution website - Download the
tar.gz
version - Unpack the file locally and
cd
into the directory - run
python setup.py install
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。