NLTK fails to find the Java executable

Thomas Chu picture Thomas Chu · Sep 13, 2011 · Viewed 18.2k times · Source

I am using NLTK's nltk.tag.stanford, which needs to call the java executable.

I set JAVAHOME to C:\Program Files\Java\jdk1.6.0_25 where my jdk is installed, but when run the program I get the error

"NLTK was unable to find the java executable! Use the config_java() or set the JAVAHOME variable"

Then I spent 3 hours on debugging it and tried

config_java("C:/Program Files/Java/jdk1.6.0_25/")

config_java("C:/Program Files/Java/jdk1.6.0_25/bin/")
and those without the ending "/". 

However the nltk still cannot find it.

Anyone has idea about what's going wrong? Thanks a loooot!

Answer

Alan picture Alan · Mar 5, 2014

If setting the JAVA_HOME environment doesn't help you, try this:

config_java() did not work for me. I add the following lines to my code and it worked:

import os
java_path = "C:/Program Files/Java/jdk1.7.0_11/bin/java.exe"
os.environ['JAVAHOME'] = java_path

I am running Windows 7 64-bit