Friday, October 28, 2016

How to fix pip install SSL certificate problems

On OSX using a previously installed Python virtualenv environment pip installs fail due to certificate problems (SEE BELOW) after upgrading python. The solution is to copy the virtualenv to a back up and reinstall the virtualenv.

https://hackercodex.com/guide/python-development-environment-on-mac-osx/

Then pip install will work in the new virtualenv. 

Don't waste time downloading certificates.

mkdir .virtualenvs/
cd .virtualenvs/
workon python.7.6.11/
virutalenv python.7.6.11/

pip install certifi
Downloading/unpacking certifi
  Downloading certifi-2016.9.26.tar.gz (374kB): 374kB downloaded
  Running setup.py egg_info for package certifi
    
Installing collected packages: certifi
  Running setup.py install for certifi
    
Successfully installed certifi
Cleaning up...

(python.7.6.11)

If that does not work then add the digital certificate to your system as describe in the Stackoverflow post below.

http://stackoverflow.com/questions/25981703/pip-install-fails-with-connection-error-ssl-certificate-verify-failed-certi/28724886#28724886



$ cd ~

$ curl -sO http://cacerts.digicert.com/DigiCertHighAssuranceEVRootCA.crt 

$ openssl x509 -inform DES -in DigiCertHighAssuranceEVRootCA.crt -out DigiCertHighAssuranceEVRootCA.pem -text

$ export PIP_CERT=`pwd`/DigiCertHighAssuranceEVRootCA.pem

# test pip with the --cert argument

# Test pip in your local env by installing the package that was failing to install 
# without the certs

pip --cert $PIP_CERT install keras

# the package should have installed correctly

# add PIP_CERT to the appropriate file depending on your OS 
# Add this line
# Replace $HOME with the full path to the directory where you have moved the cert file
export PIP_CERT=/DigiCertHighAssuranceEVRootCA.pem

# Linux
vi /Users/depappas/.bashrc
source /Users/depappas/.bashrc

# Mac OSX
 vi /Users/depappas/.bash_profile
 source /Users/depappas/.bash_profile

# check that the correct path to the cert is set in the env var
ls $PIP_CERT

pip --cert $PIP_CERT install keras

# the package should have installed correctly