I am trying to install a Python library using pip
, getting an SSL error:
~/projects/base pre-master± pip install xdict
Collecting xdict
Co
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
andpip
andwget
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 usepython3
andpip3
everywhere (unless you are in a venv/virtualenv), including thecurl
command from above:
$ curl https://bootstrap.pypa.io/get-pip.py | python3 --user