NLTK fails to find the Java executable

2019-03-09 11:10发布

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!

14条回答
一夜七次
2楼-- · 2019-03-09 11:39

I came across the same issue and this is what worked for me which is really simple. When you are setting up JavaHome variable set the path to jdk folder in your machine like below:

C:\Program Files\Java\jdk\ - This did work

C:\Program Files\Java\jdk - This did not work

查看更多
再贱就再见
3楼-- · 2019-03-09 11:39

This answer is for ubuntu 14.04 .

commenting out two lines in the batch_tag function in \nltk\tag\stanford.py

The lines are line 59 and 85.

config_java(options=self.java_options, verbose=False) and config_java(options=default_options, verbose=False) respectively.

After commenting out the lines I set the path to the Java executable in the same manner mentioned in other answers: nltk.internals.config_java("path/to/javadk/bin/java")

Everything worked fine after that.

查看更多
登录 后发表回答