Tuesday, November 1, 2011

Installing PyLucene on Ubuntu 11.10 (Oneiric Ocelot)

I recently needed to install PyLucene for our developers on a server running Ubuntu 11.10 (Oneiric Ocelot). Unfortunately the version in the repos was much too old, so I had to build it from source. Below I will describe what I did, in the hopes it will help someone else.


First, we need to install Java
sudo apt-get install openjdk-6-jre  openjdk-6-jdk ant

Download the source
http://apache.cyberuse.com//lucene/pylucene/
Extract source
tar zxvf pylucene-x.x.x-x-src.tar.gz

Try to compile jcc (it will probably fail)
cd pylucene-x.x.x-x/jcc
sudo python setup.py build
It will fail and give you a command to add a patch to setuptools, like this:
sudo patch -d /usr/lib/python2.7/dist-packages -Nup0 < /home/johnw/personal/pylucene-3.4.0-1/jcc/jcc/patches/patch.43.0.6c11
After running that, try again
sudo python setup.py build

cd to the root of the archive
cd ..

Run these commands
pushd jcc
python setup.py build
sudo python setup.py install
popd


Edit the Makefile to match your enviroment (i.e. I had to uncomment these lines)
# Linux     (Ubuntu 8.10 64-bit, Python 2.5.2, OpenJDK 1.6, setuptools 0.6c9)
#PREFIX_PYTHON=/usr
#ANT=ant
#PYTHON=$(PREFIX_PYTHON)/bin/python
#JCC=$(PYTHON) -m jcc --shared
#NUM_FILES=3

to look like this:
# Linux     (Ubuntu 8.10 64-bit, Python 2.5.2, OpenJDK 1.6, setuptools 0.6c9)
PREFIX_PYTHON=/usr
ANT=ant
PYTHON=$(PREFIX_PYTHON)/bin/python
JCC=$(PYTHON) -m jcc --shared
NUM_FILES=3

Install it
sudo make
sudo make install


Now we will run tests to make sure it installed correctly
sudo make test

If all tests complete okay, then you are all set. Enjoy!
If you feel this helped you, please leave a comment.

6 comments:

  1. Thank you for sharing this useful tutorial!

    ReplyDelete
  2. Thanks. Worked like a charm for me.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. thanks for these notes George! i am installing on ubuntu 12.04, tried to use the ancient v2.3.1 pylucene .deb before making from source. i posted a few updates re: ubuntu 12.04 64-bit, python 2.7, jdk 1.7 on stackexchange: http://stackoverflow.com/questions/12488975/only-parts-of-pylucene-are-available/

    ReplyDelete
  5. sudo python setup.py build # I got a OSerr
    cd to the root of the archive
    cd .. # must do like this?

    ReplyDelete
    Replies
    1. Which "sudo python setup.py build" are you getting the error at, and what does the error say? The first one is supposed to error out, and it gives you the command to run to fix it.

      Delete