ImportError: No module named _ssl

Ubuntu Maverick w/Python 2.7:

I can't figure out what to do to resolve the following import error:

>>> import ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/ssl.py", line 60, in <module>
   import _ssl             # if we can't import it, let the error propagate
ImportError: No module named _ssl

UPDATE: I recompiled the source. I was unable to figure out how to add the --with-ssl option the answers below mention, instead I got this to work by editing the lines regarding SSL in /Modules/Setup.dist.


Solution 1:

Unrelated to the original question, but because this is the first Google result... I hit this on Google AppEngine and had to add:

libraries:
- name: ssl
  version: latest

to app.yaml per: https://cloud.google.com/appengine/docs/python/sockets/ssl_support

Please NOTE: This seems to work upto Python version 2.7.9 but not for 2.7.10 or 2.7.11.

Solution 2:

Did you build the Python from source? If so, you need the --with-ssl option while building.