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!
I have tried all the above mentioned solutions and also the ones on Google Groups, but none worked. So after few more rounds of trial and modifications to above answers, the following piece of code worked for me :-
And then I tried NERTagger code :-
And the following was the output I received
Tested on Windows 7 64-bit
Another distinct answer for this situation is you are using an IDE such as Eclipse. Even if you have set your
JAVA_HOME
environment variable and even if you explicitly callconfig_java
and you get the[Found ... /bin/java.exe]
message returned to you, you could still have to set the runtime environment for your IDE. The reason is that when you invoke the tagger,config_java
is called again as part of the process and your original attempts at settings the path to the java binary executable can therefore be overwritten.Hopefully this saves someone else some time when trying to fix this problem. I'm pretty new to programming, Python and the NLTK, and didn't realize when I was trying to implement @dduhaime's solution that there are two 'internals.py' files: one in the nltk folder (path=C:\nltk-2.0.4 on my computer) and one in my Python27 folder (path=C:\Python27\Lib\site-packages\nltk-2.0.4-py2.7.egg\nltk on my computer). You have to add the path to the java directory on lines 69 & 72 in the latter 'internals.py' file, or the NLTK will still not be able to find it.
My environment: Windows 7 64 bit, NLTK build 2.0.4
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:I am running Windows 7 64-bit
I too have been running into problems with this. It has been such a headache!
I got this to work on my machine (Win7_x64)
Replace 'jdk1.6.0_30' with your version of the jdk. Run this command:
I do not know why it has been this difficult to get working. Hope this helps!
protos1210's tip worked for me, with a few minor changes. The full answer is:
After I restarted IDLE, the following code worked.
Output is: [('I', 'PRP'), ('hope', 'VBP'), ('this', 'DT'), ('works', 'VBZ'), ('!', '.')].
I never could get it to recognize my JAVAHOME environment variables.