Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing PyLucene on a Mac

I would like to be able to use pyLucene on my Mac. The instructions have me hopelessly lost because each instruction for setting up or making requires that I do something before it, and it's hard to know where to start and what to do from what window.

I have downloaded PyLucene. The first thing I'm wondering is where I put the folder, since that doesn't seem self-evident to me.

To use it, I am told I need to build JCC, which is included in the pylucene download.

The instructions:

At the command line, enter:

$ python setup.py build
$ sudo python setup.py install

But to do this, I think, I need to be in the right place or put the folder in the right place because otherwise I'm getting "setup.py" not found.

Any help you can offer on this environment (A shell window? An IDE?). Any help on getting pas this first part: building JCC, followed by setting up pylucene is much appreciated.

like image 926
Prof Superplum Avatar asked Jan 17 '13 10:01

Prof Superplum


2 Answers

This works on recent macOS versions. First, make sure you install:

  • Java Development Kit 8
  • Java 1.6 from Apple (due to a bug)
  • Apache Ant, ideally with Homebrew and brew install ant --with-ivy

Then add to your ~/.bash_profile:

export JAVA_HOME=$(/usr/libexec/java_home)

Then, reload your shell.

Download PyLucene and extract the folder, cd to it from your shell. Now, follow the instructions from the official installation guide:

cd jcc
python setup.py build

Now, install JCC:

python setup.py install

(A sudo may be required if you are using the macOS system Python.)

Now go back to the parent folder and edit the Makefile. Replace the uncommented lines as instructed with the actual path to ant, python, jcc, and the NUM_FILES:

ANT=ant
PYTHON=python
JCC=python -m jcc
NUM_FILES=8

Now build PyLucene:

make
make test

Finally, to install the built PyLucene:

make install

(You may need sudo if using the system Python.)

like image 65
slhck Avatar answered Sep 22 '22 02:09

slhck


Download pre-built JCC and pylucene eggs for Mac from here.

As of now, the latest versions are JCC-2.8 and lucene-3.1.0 for python 2.6, so below I'll use easy_install-2.6 and python2.6.

Install them:

$ sudo easy_install-2.6 JCC-*.egg
$ sudo easy_install-2.6 lucene-*.egg

Test:

$ python2.6
>>> import jcc
>>> import lucene
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.6/site-packages/lucene-3.1.0-py2.6-macosx-10.6-universal.egg/lucene/__init__.py", line 7, in <module>
    import _lucene
ImportError: dlopen(/Library/Python/2.6/site-packages/lucene-3.1.0-py2.6-macosx-10.6-universal.egg/lucene/_lucene.so, 2): Library not loaded: @rpath/libjcc.dylib
  Referenced from: /Library/Python/2.6/site-packages/lucene-3.1.0-py2.6-macosx-10.6-universal.egg/lucene/_lucene.so
  Reason: image not found

If you get the above error, fix it by simply creating symlink of libjcc.dylib in /usr/local/lib/. libjcc.dylib should be inside site-packages/JCC-*.egg/.

>>> jcc.__file__
'/Library/Python/2.6/site-packages/JCC-2.8-py2.6-macosx-10.7-intel.egg/jcc/__init__.pyc'
>>> ^D

$ ln -s /Library/Python/2.6/site-packages/JCC-2.8-py2.6-macosx-10.7-intel.egg/libjcc.dylib /usr/local/lib/

$ python2.6
>>> import jcc, lucene
>>> 
like image 36
suzanshakya Avatar answered Sep 20 '22 02:09

suzanshakya