Matteo
Matteo

Reputation: 8132

Stanford CoreNLP python interface installation errors

I'm trying to build the python interface of the stanford NLP on Ubuntu 12.04.5 LTS. There are two steps required, the first of which is:

  1. compile Jpype by running "rake setup" in 3rdParty/jpype

When doing so I get the following error:

In file included from src/native/common/jp_monitor.cpp:17:0:
src/native/common/include/jpype.h:45:17: fatal error: jni.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
rake aborted!
Command failed with status (1): [cd JPype-0.5.4.1 && python setup.py build...]

The error messages says I'm missing jni.h, so as suggested here if I ran the command dpkg-query -L openjdk-7-jdk | grep "jni.h" getting /usr/lib/jvm/java-7-openjdk-amd64/include/jni.h.

I believe that means I do have jni.h on my system, so I'm very confused right now. What is causing the error? Can you suggest any fix?

Thanks for your help!


A FEW MORE INSIGHTS

Here is the instruction causing the error:

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/lib/jvm/java-1.5.0-sun-1.5.0.08/include -I/usr/lib/jvm/java-1.5.0-sun-1.5.0.08/include/linux -Isrc/native/common/include -Isrc/native/python/include -I/usr/include/python2.7 -c src/native/common/jp_class.cpp -o build/temp.linux-x86_64-2.7/src/native/common/jp_class.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for Ada/C/ObjC but not for C++ [enabled by default]
In file included from src/native/common/jp_class.cpp:17:0:src/native/common/include/jpype.h:45:17: fatal error: jni.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1

It's coming from the compilation of JPype needed for the python interface. I do not know why but it includes paths that I don't have in my filesystem (i.e. -I/usr/lib/jvm/java-1.5.0-sun-1.5.0.08/include/linux).

How can I configure these paths correctly?

Upvotes: 5

Views: 820

Answers (3)

Matteo
Matteo

Reputation: 8132

This problem is a path problem (as said in the question and correctly answered by @vikramls).

Apparently when running the script for installing the python interface of the StanfordNLP if JPype is missing it will get installed with the following command:

python setup.py install

Now if you open the file setup.py you can see the following part which sets the java paths for a linux machine (I'm running on ubuntu):

def setupLinux(self):
    self.javaHome = os.getenv("JAVA_HOME")
    if self.javaHome is None :
        self.javaHome = '/usr/lib/jvm/java-1.5.0-sun-1.5.0.08' # Ubuntu linux
        # self.javaHome = '/usr/java/jdk1.5.0_05'    
    self.jdkInclude = "linux"    
    self.libraries = ["dl"]
    self.libraryDir = [self.javaHome+"/lib"]

Clearly this path will not work on every machine, so there are 2 possible solutions:

  1. Before running the installation script export a variable called JAVA_HOME with the location of your java installation. I.e. export JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64 in my case.

  2. As this page says you can set an automatic include variable for gcc with the following command export C_INCLUDE_PATH=some_path and that path should be set to where you java libraries are on your machine

Upvotes: 0

kichik
kichik

Reputation: 34704

Based on the following question, it seems like you can fix this by setting JAVA_HOME.

JPype compile problems

So before building use:

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

Upvotes: 2

vikramls
vikramls

Reputation: 1822

The include paths specified do not include the path where jni.h is located.

From your grep, jni.h is located here: /usr/lib/jvm/java-7-openjdk-amd64/include/jni.h

The include paths specified in the gcc args are: -I/usr/lib/jvm/java-1.5.0-sun-1.5.0.08/include -I/usr/lib/jvm/java-1.5.0-sun-1.5.0.08/include/linux -Isrc/native/common/include -Isrc/native/python/include -I/usr/include/python2.7

Sounds to me that you are building with the wrong java? You have a java-1.5.0 install and a java-7-openjdk install - this one has the missing jni.h file.

Upvotes: 2

Related Questions