virtualenv lessons learned

In the time since first diving into virtualenv I’ve learned a couple things.  First, between easy_install and pip, use pip: it’s smarter and does what I want, which is to extract top-level packages directly into the site-packages directory.  Second, sometimes it’s easier to symlink a package into the virtualenv site-packages from the system Python’s site-packages dir — just remember that you may have to point specifically to the 64-bit version in /usr/lib64 (CentOS).  I found this to be the case in particular for the Python Subversion bindings required for Trac.  I could not figure out, in a reasonable amount of time, where to even get the sources, so I decided to symlink in the svn and libsvn packages install in the OS site-packages dir, and it seems to work fine.  On a related note, you can run a non-virtualenv app under WSGI even if WSGI is configured for virtualenv by simply setting the site directories in the WSGI script:

import site
# add 64-bit lib first
site.addsitedir('/usr/lib64/python2.4/site-packages')
site.addsitedir('/usr/lib/python2.4/site-packages')

And the fun continues …

Advertisements