I am trying to install a Python library using pip
, getting an SSL error:
~/projects/base pre-master± pip install xdict
Collecting xdict
Co
myenv:
python 2.7.14
pip 9.0.1
mac osx 10.9.4
mysolution:
download get-pip.py
manually from https://packaging.python.org/tutorials/installing-packages/
run python get-pip.py
refs:
https://github.com/pypa/warehouse/issues/3293#issuecomment-378468534
https://packaging.python.org/tutorials/installing-packages/
Securely Download get-pip.py [1]
Run python get-pip.py. [2] This will install or upgrade pip. Additionally, it will install setuptools and wheel if they’re not installed already.
Ensure pip, setuptools, and wheel are up to date
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:
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. 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 :-).
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.
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.
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
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.