haystack, xapian and virutalenv
Ok, so I finally added the use of virtualenv to my python development process. The whole isolationist sandbox approach gives me the warm fuzzes. And now that I’m happy with the approach, I want to extend it into use into production environments I’m deploying.
In the current django project I’m working to deploy, I’m running into some interesting little hoops I have to jump through in order to effectively get the project sandboxed. One such case is making xapian available to the sandboxed django (through haystack).
Now to give you some background on my production environment, I’m running with a default install of ubuntu, which includes xapian and the bindings specific to the system version of python. But because I’ve add “–no-site-packages” to my virtualenv, I can’t actually make use of it. With a little bit of google fu, I was actually able to find two completely separate solutions on the first search page.
With the first solution, I was given a bit of hope that it would be simple. This mail thread explains that you could just symbolically link the library into your virtualenv. Ok, simple enough but I just couldn’t get it to work. No worries, there was another solution to try.
The second solution really is just a script posted to gist. Simply put, it installs xapian and the bindings into the sandboxed directory for the virtualenv.
Now in my development environment on my laptop, I run xapian (and practically everything else I use for development) like this. In a production environment though, I try to not install development tools (compilers and such). Following the steps in this script (or running the script itself) means I need to install those tools. Not quite what I wanted but c’est la vie.
After some modification to the script, I was able to get things up and running. Django is happy and able to utilize xapian via haystack.
Here’s the modified script I used for review:
export VENV=$VIRTUAL_ENV
mkdir $VENV/packages && cd $VENV/packages
wget http://oligarchy.co.uk/xapian/1.2.7/xapian-core-1.2.7.tar.gz
wget http://oligarchy.co.uk/xapian/1.2.7/xapian-bindings-1.2.7.tar.gz
tar xzvf xapian-core-1.2.7.tar.gz
tar xzvf xapian-bindings-1.2.7.tar.gz
cd $VENV/packages/xapian-core-1.2.7
./configure --prefix=$VENV && make && make install
export LD_LIBRARY_PATH=$VENV/lib
cd $VENV/packages/xapian-bindings-1.2.7
./configure --prefix=$VENV --with-python --without-ruby --without-perl --without-php --without-tcl
make && make install
python -c "import xapian"