Tags

, , , , , ,

If you want to install pylucene automatically, try Synaptic package manager or apt-get. This installation gives you Pylucene2.3. This is old. If you wish to get the latest pylucene 3.6 or higher, please look for manual installation discussed in this post.

Automatic installation (pylucene 2.3)

  • Install everything mentioned here
  • sudo apt-get install pylucene
  • sudo apt-get install python-dev
  • I borrowed a test program from here. The immediate error you would see if you try to run a pylucene based program is:
kanaujia@ubuntu:~/work/Py$ python myluce.py 
Traceback (most recent call last):
  File "myluce.py", line 11, in 
    import lucene
  File "/usr/lib/python2.7/dist-packages/lucene/__init__.py", line 2, in 
    import os, _lucene
ImportError: libjvm.so: cannot open shared object file: No such file or directory
  • Run following:
    $ ldconfig -p | grep libjvm

    If you find nothing, see the next point.

  • Make sure you have Java JDK/ JRE available on your machine.
    root@ubuntu:~# find / -type f -name libjvm.so 
            /usr/lib/jvm/java-6-openjdk-i386/jre/lib/i386/cacao/libjvm.so
    /usr/lib/jvm/java-6-openjdk-i386/jre/lib/i386/server/libjvm.so
    /usr/lib/jvm/java-6-openjdk-i386/jre/lib/i386/client/libjvm.so
    /usr/lib/jvm/java-6-openjdk-i386/jre/lib/i386/jamvm/libjvm.so
  • Export the path to your library.
    root@ubuntu:~/work/Py$ export LD_LIBRARY_PATH=
    /usr/lib/jvm/java-6-openjdk-i386/jre/lib/i386/server:$LD_LIBRARY_PATH
  • And, you are done 🙂
    root@ubuntu:~/work/Py$ python myluce.py
    Usage:
    myluce.py <field_name> <index_url>

Installing Pylucene 3.0 or higher version manually

  1. Install everything mentioned here
  2. wget https://bootstrap.pypa.io/ez_setup.py -O - | python
  3. sudo apt-get install python-dev
  4. Get the package from http://lucene.apache.org/pylucene
  5. Find out the JVM path on your machine
  6. $ sudo update-java-alternatives -l
    java-1.6.0-openjdk-i386 1061 /usr/lib/jvm/java-1.6.0-openjdk-i386
  7. Now goto your pylucene package, unzip and untar.

Note: I am following instructions at: http://lucene.apache.org/pylucene/install.html

  • cd ./pylucene-3.6.1-2/
  • pushd jcc
  • <edit setup.py to match your environment>

Open setup.py, and search for “JDK”. Update the JDK path to what you found in step 3.

  • 51 JDK = {
     52     'darwin': JAVAHOME,
     53     'ipod': '/usr/include/gcc',
     54     #'linux2': '/usr/lib/jvm/java-6-openjdk',
     55     'linux2': '/usr/lib/jvm/java-1.6.0-openjdk-i386',
     56     'sunos5': '/usr/jdk/instances/jdk1.6.0',
     57     'win32': JAVAHOME,
     58     'mingw32': JAVAHOME,
     59     'freebsd7': '/usr/local/diablo-jdk1.6.0'
     60 }
    • python setup.py build
    • sudo python setup.py install
    • popd
    • <edit Makefile to match your environment>
    $ vi Makefile

    Uncomment following:

     48 # Mac OS X 10.6 (64-bit Python 2.6, Java 1.6)
     49 PREFIX_PYTHON=/usr
     50 ANT=ant
     51 PYTHON=$(PREFIX_PYTHON)/bin/python
     52 JCC=$(PYTHON) -m jcc.__main__ --shared --arch x86_64
     53 NUM_FILES=4
    • make

    This ‘make’ is very very slow. On my dual core laptop, it took about 15 minutes to complete.

    • sudo make install
    • make test (look for failures)
    • Done… sigh (Thanks a bunch to this blog)
Advertisements