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
Homebrew
This was probably caused by an upgrade to Mavericks. Here's how I fixed it.
Update OpenSSL
Reinstall Python
Python 3
Python 2
This answer consolidates all the Stack Exchange answers and comments I found, and is based mostly on this Apple Stack Exchange answer.
In many cases this is caused by an out of date virtualenv, here's a script to regenerate your virtualenv(s): https://gist.github.com/WoLpH/fb98f7dc6ba6f05da2b8
Simply copy it to a file (downloadable link above) and execute it like this:
zsh -e recreate_virtualenvs.sh <project_name>
OSX + homebrew users:
You can get the latest updates to the recipe:
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:
To get the latest openssl:
This may issue a warning:
Side note: this warning means that for other apps, you may want to use
Then recompile python:
or for python 3
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.I'm using Redhat and have met the same problem.
My solution is :
If I didn't do the 2nd step, when I recompiled my python2.7 , the log would say " fail to build module _ssl".