Skip to content Skip to sidebar Skip to footer

Call Python From Java Code Using Jython Cause Error: Importerror: No Module Named Nltk

I'm calling a python code from a java code using jython by PythonInterpreter. the python code just tag the sentence: import nltk import pprint tokenizer = None tagger = None d

Solution 1:

Now that the compile-time syntax error is solved, you are getting run-time errors. What is nltk? Where is nltk? The ImportError implies that nltk is not in your import path.

Try writing a small simple program and examine sys.path ; you might need to append location of nltk before importing it.

### The import fails if nltk is not in the system path:>>> import nltk
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named nltk

### Try inspecting the system path:>>> import sys
>>> sys.path
['', '/usr/lib/site-python', '/usr/share/jython/Lib', '__classpath__', '__pyclasspath__/', '/usr/share/jython/Lib/site-packages']

### Try appending the location of nltk to the system path:>>> sys.path.append("/path/to/nltk")

#### Now try the import again.

Post a Comment for "Call Python From Java Code Using Jython Cause Error: Importerror: No Module Named Nltk"