SSL Certificate Error Using `pip install`

If you’ve recently been seeing an error message while using pip install stating that ‘There was a problem confirming the ssl certificate’, there is a good possibility that it is related to a recent pypi website change, which seems to have broken pip installations for many people.

Photo by Tom Butler on Unsplash

Issue

I was getting the following message while installing Flask in a virtual environment:

(env) MacBook-Pro:flask-app jane$ pip install flask
Collecting flask
Could not fetch URL https://pypi.python.org/simple/flask/: There was a problem confirming the ssl certificate: EOF occurred in violation of protocol (_ssl.c:590) — skipping
Could not find a version that satisfies the requirement flask (from versions: )
No matching distribution found for flask

Solution

Some places on the net advised to install the pypi host as trusted, while others recommended different hacks. None of those suggestions worked, so I kept looking until this pypa-dev ticket comment on github hit the spot. The comment suggested to upgrade both pip and virtualenv.

Upgrading pip in the system Python Installation

  1. Check the pip version before the upgrade (to verify the update later):
    MacBook-Pro:~ jane$ pip --version
    pip 9.0.1 from /Library/Python/2.7/site-packages (python 2.7)
  2. Download get-pip.py.
  3. Run the following command to upgrade pip:
    MacBook-Pro:~ jane$ sudo python get-pip.py
  4. Verify the version of pip:
    MacBook-Pro:~ jane$ pip --version
    pip 9.0.3 from /Library/Python/2.7/site-packages (python 2.7)
Note: For pip to work in existing virtual environments, you will need to follow same steps as above to upgrade pip. After activating the virtual environment, run Step 3 without the sudo. You can use the same get-pip.py downloaded in Step 2 above.

Upgrading virtualenv

I noticed that after upgrading system pip, the newer virtual environments created using virtualenv were still using the old pip version and I was still getting the SSL certificate error message. I had to also upgrade virtualenv to resolve the issue.

  1. Check the version of virtualenv before the upgrade:
    MacBook-Pro:~ jane$ virtualenv --version
    15.1.0
  2. Run the following command to upgrade virtualenv:
    MacBook-Pro:~ jane$ sudo pip install --upgrade virtualenv
    Collecting virtualenv
     Downloading virtualenv-15.2.0-py2.py3-none-any.whl (2.6MB)
     100% |████████████████████████████████| 2.6MB 385kB/s
    Installing collected packages: virtualenv
     Found existing installation: virtualenv 15.1.0
     Uninstalling virtualenv-15.1.0:
     Successfully uninstalled virtualenv-15.1.0
    Successfully installed virtualenv-15.2.0
Note: Updating virtualenv ensures that the virtual environments that you create in future will install the latest pip version as well (otherwise you would need to upgrade pip version individually in every future virtual environment you create).

Thereafter, I was able to successfully install flask (and perform other pip install operations) in a virtual environment.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.