Not able to install Python packages [SSL: TLSV1_AL

2018-12-31 02:06发布

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?

13条回答
素衣白纱
2楼-- · 2018-12-31 02:37

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.

查看更多
有味是清欢
3楼-- · 2018-12-31 02:41

And for Python 3 users, curl needs to be piped to python3:

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

If any of the above curl commands fail with the same "tlsv1 alert protocol version" error, please ensure your system's underlying OpenSSL library is at least version 1.0.1, for TLS v1.2 to work.

Both curl and pip (and wget) depend on OpenSSL for establishing SSL connections. The version can be verified with $ openssl version command.

libcurl itself supports TLS 1.2 since curl version 7.34, but older versions should also be able to connect if you have OpenSSL version 1.0.2 (or later), which uses TLS 1.2 by default. If you are lacking tools such as curl and cannot install it, it is also possible to download get-pip.py (or the pip package itself) using your favourite web browser...

Finally, if still no-go, another thing that can help (especially for older OS/Python versions) is to ensure the following Python packages (dependencies related to SSL and pip functioning) are installed: pyasn1, certifi, asn1crypto, cryptography, pyOpenSSL, urllib3

You can check which one is missing by trying this import in Python interpreter:

>>> import pyasn1, certifi, asn1crypto, cryptography, OpenSSL, urllib3

Because pip cannot connect (yet), just download their latest wheels from pypi.org via your favourite web browser one by one, and install using pip install --user <package-file.whl> command (or pip3 for Python 3) in the same order as listed above to resolve pip dependencies.

Note: It should be preceded with a shell command $ sudo apt-get install build-essential libssl-dev libffi-dev python-dev (or python3-dev in case of Python 3) to ensure these Python packages can be built.

查看更多
有味是清欢
4楼-- · 2018-12-31 02:43

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 situation of mine:

  1. Check the pip.ini (usually under the path C:\ProgramData\pip) had been modified;

  2. If yes in step1, try to reset it to a default configuration.

查看更多
深知你不懂我心
5楼-- · 2018-12-31 02:44

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

查看更多
千与千寻千般痛.
6楼-- · 2018-12-31 02:44

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楼-- · 2018-12-31 02:44

This worked for me. Add sudo before python

curl https://bootstrap.pypa.io/get-pip.py |sudo python
查看更多
登录 后发表回答