Monday, November 18, 2013

Installing PyLucene 4 (4.5.1)

Greetings friends!

Here I'm going to show you how to install/setup pylucene 4.x on linux - ubuntu or debian

Why are we installing pylucene 4?

This may be your first time using lucene with Python, or you may be upgrading.  pylucene 4 adds faceting features, and reworks the module structure to be identical to that of lucene 4 itself.  Check out the samples directory after you download the pylucene package for examples of new and existing functionality.

Install PyLucene

Download pylucene from

Extract the Package:
tar -zxvf pylucene-4.5.1-src.tar.gz
Install openjdk:
sudo apt-get install openjdk-7-jdk
Install Apache Ant:
sudo apt-get install ant
Install gnu c++ compiler:
sudo apt-get install g++

Install python dev (python.h) headers:
sudo apt-get install python-dev

Upgrade/install setuptools to 0.7 or higher:
sudo apt-get install pip 
pip install setuptools --upgrade 

Change to the jcc directory:
cd pylucene-4.5.1-1/jcc  (edit to match your extracted directory)
Build and Install JCC:
sudo python build
sudo python install 
If all that worked, you're ready to build pylucene!
# cd up to the "" directory 
cd .. 

Edit the file named "Makefile" located at the root of the pylucene-4.5.1 directory you just extracted
# Locate this line
# Linux     (Ubuntu 11.10 64-bit, Python 2.7.2, OpenJDK 1.7, setuptools 0.6.16)
Uncomment lines in the Makefile as shown (if you are on linux):

Issue make and install command:
sudo make install  
 Test the installation:
# open a python interpreter 
# now at the prompt type... 
import lucene 

 If no exceptions are raised you're done!  You've now installed PyLucene 4 !

Troubleshooting Errors

Traceback (most recent call last):  File "", line 418, in
    main('--debug' in sys.argv)  File "", line 363, in main    raise type(e), "%s: %s" %(e, args)OSError: [Errno 2] No such file or directory: ['javac', '-d', 'jcc/classes', 'java/org/apache/jcc/', 'java/org/apache/jcc/']

What this error is really telling us is it couldn't find "javac" ... This is a program provided by the debian/ubuntu package "openjdk-7-jdk" Install this package and try again.

jcc/sources/jcc.cpp:18:17: fatal error: jni.h: No such file or directory #include
                 ^compilation terminated.
This error happens when the sources path can't be found for  your jdk (or JRE)... or you have the wrong jdk installed. If you get this error it means you are using a jdk that the installer isn't looking for.  Open pylucene-4.5.1-1/jcc/ with a text editor.  Look for a line similar to this: 

    'linux2': '/usr/lib/jvm/java-7-openjdk-amd64',

Whatever the value of the JDK here is.. is the one you need installed.  In my case "openjdk-7-jdk"

*** ANT is not defined, please edit Makefile as required at top. Stop.

This means you didn't edit a section of the file named Makefile to uncomment the variables needed to run the makefile.


  1. Hi thanks for the nice instructions on installing pylucene on ubuntu. I've tried it and I have this error that I can't fix. Have you any idea how I can go about fixing it?

  2. Hi,
    I followed all the above instructions,but at the make stage I am getting the following error:
    Traceback (most recent call last):
    File "/usr/lib/python2.7/", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
    File "/usr/lib/python2.7/", line 72, in _run_code
    exec code in run_globals
    File "/usr/local/lib/python2.7/dist-packages/jcc/", line 107, in
    File "/usr/local/lib/python2.7/dist-packages/jcc/", line 735, in jcc
    egg_info, extra_setup_args)
    File "/usr/local/lib/python2.7/dist-packages/jcc/", line 1611, in compile
    raise ImportError, 'setuptools is required when using --shared'
    ImportError: setuptools is required when using --shared
    Makefile:363: recipe for target 'compile' failed
    make: *** [compile] Error 1

    Please help!!

    1. Hey Vaibhav, make sure you have setuptools, and the latest verson.

      #ensure you have pip
      sudo apt-get install python-pip

      # upgrade pip
      sudo pip install --upgrade --no-use-wheel pip

      # upgrade/install setuptools
      sudo pip install --upgrade setuptools

  3. Free easy & simple way to learn java online and much more.. go to =>>

  4. Hey, just in case anyone is having trouble with "Ivy" on Fedora 26 I had to install apache-ivy as well.

    #dnf install apache-ivy