pip install error – [SSL: TLSV1_ALERT_PROTOCOL_VERSION]

I am on osx. And for my particular project I am stuck with python 2.7. (I think python 3 is fine at the moment.) Apparently pip has been acting up. If you do a pip install and getting something like this:

Collecting alembic==0.9.5 (from -r requirements.txt (line 1))
  Could not fetch URL https://pypi.python.org/simple/alembic/: 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 alembic==0.9.5 (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for alembic==0.9.5 (from -r requirements.txt (line 1))

Check your pip version. pip –version. If you have 9.0.1, that’s the bad version. You will need to get to 9.0.2 or 9.0.3, or maybe version 10, but I will explain later.

If you do pip install –upgrade pip==9.0.3, that will fail with the same ssl error.

Don’t do curl https://bootstrap.pypa.io/get-pip.py | python at this point, because that will give you the pip version 10, which you may keep getting errors like this whenever you use pip.

from pip._internal import main
ImportError: No module named _internal

If you are making a system-wide change to your pip, then here is how. First remove pip, then install it back.

sudo pip uninstall pip
python -m ensurepip
curl https://bootstrap.pypa.io/2.6/get-pip.py | python

The python -m ensurepip will give you pip 6.1.1, then the get-pip.py call will give you pip 9.0.3. Then you are all set.

If you are making a change to a virtual environment, depending on which python (-p) param you provide, mkvirtualenv always gives me pip 9.0.1 (bad) or pip 10 (bad).

If you end up having pip 10, try pip install pip==9.0.3. If that works then good for you, you can stop here. Otherwise, do the following.

We will need to install another version of python from homebrew.

brew install python2
mkvirtualenv -p /usr/local/Cellar/python\@2/2.7.14_3/bin/python2.7 your_env_name
pip --version
pip install pip==9.0.3

After the mkvirtualenv call, the pip version is 10. Then you can downgrade to 9.0.3.

That’s all if you have to stick with python 2.7. My other projects using python 3 seem ok.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s