ImportError: cannot import name HTTPSHandler using PIP
Solution 1
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 -a
which openssl
To get the latest openssl:
brew update
brew install openssl
brew link --overwrite --dry-run openssl # safety first.
brew link openssl --overwrite
This may issue a warning:
bash-4.3$ brew link --overwrite --dry-run openssl
Warning: 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/lib
export CPPFLAGS=-I/usr/local/opt/openssl/include
Then recompile python:
brew uninstall python
brew install python --with-brewed-openssl
or for python 3
brew uninstall python3
brew install python3 --with-brewed-openssl
Solution 2
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.
Solution 3
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 case
sudo cp /usr/bin/openssl /usr/bin/openssl.apple
# update openssl
brew update
brew install openssl
brew link --force openssl
# reload terminal paths
hash -r
Reinstall Python
Python 3
brew uninstall python3
brew install python3 --with-brewed-openssl
Python 2
brew uninstall python
brew 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.
Solution 4
I was having this problem on Mac OSX, even after confirming my PATH, etc.
Did a; pip uninstall virtualenv then install virtualenv and it seemed to works now.
At the time I had forced brew to link openssl, unlinked it and virtualenv still seems to work but maybe that's because it was originally linked when I reinstalled it.
Solution 5
You need to install OpenSSl before make and install Python to solve the problem.
On Centos:
yum install openssl openssl-devel -y
user3016020
Updated on July 08, 2022Comments
-
user3016020 almost 2 years
Facing an HTTPSHandler error while installing python packages using pip, following is the stack trace,
--------desktop:~$ pip install Django==1.3 Traceback (most recent call last): File "/home/env/.genv/bin/pip", line 9, in <module> load_entry_point('pip==1.4.1', 'console_scripts', 'pip')() File "/home/env/.genv/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/home/env/.genv/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point return ep.load() File "/home/env/.genv/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load entry = __import__(self.module_name, globals(),globals(), ['__name__']) File "/home/env/.genv/lib/python2.7/site-packages/pip/__init__.py", line 10, in <module> from pip.util import get_installed_distributions, get_prog File "/home/env/.genv/lib/python2.7/site-packages/pip/util.py", line 17, in <module> from pip.vendor.distlib import version File "/home/env/.genv/lib/python2.7/site-packages/pip/vendor/distlib/version.py", line 13, in <module> from .compat import string_types File "/home/env/.genv/lib/python2.7/site-packages/pip/vendor/distlib/compat.py", line 31, in <module> from urllib2 import (Request, urlopen, URLError, HTTPError, ImportError: cannot import name HTTPSHandler
I used to edit Modules/setup.dist file and uncomment SSL code lines and rebuilt it, with reference to following thread : http://forums.opensuse.org/english/get-technical-help-here/applications/488962-opensuse-python-openssl-2.html
-
user3016020 over 10 yearsHey thankks, yes, it required some dependancies, and it is working now.
-
tdc over 9 yearsDon't think this will work if you have multiple python versions installed
-
Cam.Davidson.Pilon over 9 yearsDaniel and I get a permission denied error. any idea?
-
David Wright about 9 yearsI should have been pointing to
/usr/local/Cellar/python/whatever_version_number/bin/python
not/usr/local/Cellar/python/whatever_version_number/
Made the change above. I hope you and Daniel got it working. -
HDJEMAI over 8 yearsI installed openssl, but i still have a problem for building python 2.7.10
-
HDJEMAI over 8 yearsmessage: python get-pip.py Traceback (most recent call last): File "get-pip.py", line 17759, in <module> main() File "get-pip.py", line 162, in main bootstrap(tmpdir=tmpdir) File "get-pip.py", line 82, in bootstrap import pip
-
HDJEMAI over 8 yearsFile "/tmp/tmpaVpnhQ/pip.zip/pip/__init__.py", line 15, in <module> File "/tmp/tmpaVpnhQ/pip.zip/pip/vcs/subversion.py", line 9, in <module> File "/tmp/tmpaVpnhQ/pip.zip/pip/index.py", line 30, in <module> File "/tmp/tmpaVpnhQ/pip.zip/pip/wheel.py", line 35, in <module> File "/tmp/tmpaVpnhQ/pip.zip/pip/_vendor/distlib/scripts.py", line 14, in <module> File "/tmp/tmpaVpnhQ/pip.zip/pip/_vendor/distlib/compat.py", line 31, in <module> ImportError: cannot import name HTTPSHandler
-
Perspective almost 8 yearsPrefect, I was getting the
ImportError: cannot import name HTTPSHandler
on El Capitan 10.11 beta, and I just ended up usingbrew update
andbrew install openssl
since I had pip and python already installed. Thank you -
Mona Jalal almost 8 years
bash-4.3$ brew link --overwrite --dry-run openssl Warning: 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
-
christang over 7 yearsThanks! note:
brew upgrade
not only reinstalls python, but other modules that may be out of date as well all at once. This may take a few minutes depending on other things you have installed. -
MillerMedia over 4 yearsWhen I try
brew install python3 --with-brewed-openssl
I receive the errorError: invalid option: --with-brewed-openssl
. Is there an update to this answer? -
tHeSiD almost 4 yearsUse the comments feature to interact with the users instead of posting your comment as an answer.