ImportError: cannot import name HTTPSHandler using PIP ImportError: cannot import name HTTPSHandler using PIP python python

ImportError: cannot import name HTTPSHandler using PIP


OSX + homebrew users:

You can get the latest updates to the recipe:

brew reinstall python

But if you still get the issue, e.g. maybe you have upgraded your OS, then you may need to get the latest openssl first. You can check which version and where it is used from:

openssl version -awhich openssl

To get the latest openssl:

brew updatebrew install opensslbrew link --overwrite --dry-run openssl  # safety first.brew link openssl --overwrite

This may issue a warning:

bash-4.3$ brew link --overwrite --dry-run opensslWarning: Refusing to link: openssl Linking keg-only openssl means you may end up linking against the insecure, deprecated system OpenSSL while using the headers from Homebrew's openssl. Instead, pass the full include/library paths to your compiler e.g.: -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib

Side note: this warning means that for other apps, you may want to use

export LDFLAGS=-L/usr/local/opt/openssl/libexport CPPFLAGS=-I/usr/local/opt/openssl/include

Then recompile python:

brew uninstall pythonbrew install python --with-brewed-openssl

or for python 3

brew uninstall python3brew install python3 --with-brewed-openssl


You need to install the OpenSSL header files before building Python if you need SSL support. On Debian and Ubuntu, they are in a package called libssl-dev. You might need some more dependencies, as noted here.


Homebrew

This was probably caused by an upgrade to Mavericks. Here's how I fixed it.

Update OpenSSL

#make a copy of the existing library, just in casesudo cp /usr/bin/openssl /usr/bin/openssl.apple# update openssl brew updatebrew install opensslbrew link --force openssl# reload terminal pathshash -r

Reinstall Python

Python 3

brew uninstall python3brew install python3 --with-brewed-openssl

Python 2

brew uninstall pythonbrew install python --with-brewed-openssl

This answer consolidates all the Stack Exchange answers and comments I found, and is based mostly on this Apple Stack Exchange answer.