System SSL settings don't carry through to virtualenv
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Virtualenv |
In Progress
|
Undecided
|
Unassigned |
Bug Description
SSL support in Python doesn't always work out the box, especially when using virtualenv.
You'll know you have a problem when you an error similar to the following:
AttributeError: 'module' object has no attribute 'ssl'
If you are receiving this using your system Python installation, as well as your virtualenv you'll need to follow Patrick Altman's instructions: http://
However, after completing the above you will find that your system python passes the following quick test:
$ python
>>> import socket
>>> hasattr(socket, "ssl")
True
BUT your virtualenv:
/path/to/
Fails the same test:
$ python
>>> import socket
>>> hasattr(socket, "ssl")
False
It seems that virtualenv has problems picking up ssl settings, especially, in my experience, when openssl is installed after virtualenv. Creating fresh environments has no effect.
To get round the problem, try the following:
Via your system python:
$ python
>>> import _ssl
>>> _ssl.__file__
You should get a path similar to (DO NOT modify anything in this directory):
/usr/local/
Copy or symlink that to file in your virtualenv python site-packages folder:
cp /usr/local/
And it should all work fine. Test it in your virtualenv via the same command from earlier:
/var/odbody/
>>> import socket
>>> hasattr(socket, "ssl")
True
I believe this to be a bug in virtualenv and have reported it as such here. Although I'd happily be proved otherwise!
(Many thanks to mgedmin in #zope3-dev for his help with this problem)
So I guess the problem in this case is that /usr/lib/ python2. 5/lib-dynload is being symlinked over, and so it will work, but /usr/local/ lib/python2. 5/lib-dynload is not.
These directories aren't determined in site.py, but sometime earlier (which is why the symlink is necessary). However, stuff in /usr/local/ probably isn't as critical, so it can be added at a later time.
I think I've fixed this in r3804. It doesn't copy over anything from lib-dynload, but should add that to the path.