NLTK fails to find the Java executable NLTK fails to find the Java executable python python

NLTK fails to find the Java executable


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 osjava_path = "C:/Program Files/Java/jdk1.7.0_11/bin/java.exe"os.environ['JAVAHOME'] = java_path

I am running Windows 7 64-bit


I spent about seven hours working through this problem, and finally found a solution. You can write your java directory right into lines 69 and 72 of the internals.py file (build 2.0.4) as follows:

########################################################################### Java Via Command-Line##########################################################################_java_bin = 'C:\Program Files\Java\jdk1.7.0_25\\bin\java.exe'_java_options = []# [xx] add classpath option to config_java?def config_java(bin='C:\Program Files\Java\jdk1.7.0_25\\bin\java.exe', options=None, verbose=True):

This resolves the problem for me. (I'm working in a 32 bit Windows environment)


protos1210's tip worked for me, with a few minor changes. The full answer is:

import nltknltk.internals.config_java("C:/Program Files/Java/jdk1.6.0_30/bin/java.exe")

After I restarted IDLE, the following code worked.

import nltkpath_to_model = "C:/Program Files/stanford-postagger-2012-05-22/models/english-bidirectional-distsim.tagger"path_to_jar = "C:/Program Files/stanford-postagger-2012-05-22/stanford-postagger.jar"tagger = nltk.tag.stanford.POSTagger(path_to_model, path_to_jar)tokens = nltk.tokenize.word_tokenize("I hope this works!")print tagger.tag(tokens)

Output is: [('I', 'PRP'), ('hope', 'VBP'), ('this', 'DT'), ('works', 'VBZ'), ('!', '.')].

I never could get it to recognize my JAVAHOME environment variables.