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 http://lucene.apache.org/pylucene/install.html

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 setup.py build
sudo python setup.py install 
If all that worked, you're ready to build pylucene!
# cd up to the "pylucene-4.xxx" 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:
make 
sudo make install  
 Test the installation:
# open a python interpreter 
python 
# now at the prompt type... 
import lucene 
lucene.initVM()

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



Troubleshooting Errors

Error:
Traceback (most recent call last):  File "setup.py", line 418, in
    main('--debug' in sys.argv)  File "setup.py", 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/PythonVM.java', 'java/org/apache/jcc/PythonException.java']

Solution:
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.



Error:
jcc/sources/jcc.cpp:18:17: fatal error: jni.h: No such file or directory #include
                 ^compilation terminated.
Solution:
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/setup.py 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"




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

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

11 comments:

  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? http://stackoverflow.com/questions/26904725/pylucene-error-with-icetea-jdk-jre

    ReplyDelete
  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/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
    File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
    File "/usr/local/lib/python2.7/dist-packages/jcc/__main__.py", line 107, in
    cpp.jcc(sys.argv)
    File "/usr/local/lib/python2.7/dist-packages/jcc/cpp.py", line 735, in jcc
    egg_info, extra_setup_args)
    File "/usr/local/lib/python2.7/dist-packages/jcc/python.py", 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!!

    ReplyDelete
    Replies
    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

      Delete
  3. Free easy & simple way to learn java online and much more.. go to =>> http://foundjava.blogspot.in

    ReplyDelete
  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

    ReplyDelete
  5. I can't seem to fix this jcc error: jcc not installed as a shared library.
    I have updated pip and setuptools still not working, helo

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

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

    ReplyDelete
  8. Hi. Thanks for the article. I am stuck at the end ie make installation.
    Below is the error I am getting. Could you help to sort it out?

    NotImplementedError: JCC was not built with --shared mode support, see JCC's INSTALL file for more information
    make: *** [Makefile:385: compile] Error 1


    ReplyDelete
  9. I am facing the issue while installing Java8 for Pylucene using command:

    sudo apt-get install oracle-java8-installer

    and I got following:

    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    Package oracle-java8-installer is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or
    is only available from another source

    E: Package 'oracle-java8-installer' has no installation candidate

    ===================
    Note: my Pylucene version is pylucene-7.7.1

    I tried but not able install java8 using oracle-java8-installer, that is recommended by Pylucene library in there code of file setup.py

    Please let me know how I can make it working in ubuntu 18.04?

    However, I followed step from https://gist.github.com/avivzk2/10c88b37d280f873cf72a9a344755368

    ReplyDelete