Issues while calling nltk libraries using jython

2019-03-02 07:33发布

问题:

I am trying to call nltk libraries which are integrated in my python code. As per requirement I need to call them through my java code, therefore, I am using Jython for the integration. If my pyhton code does not includes any nltk library, in such case it works fine. But when it includes nltk library, it gives me import error. I have already added nltk related system paths to the interpreter

PySystemState sys = Py.getSystemState();
sys.path.append(new PyString("c:\\Python27\\Lib"));
sys.path.append(new PyString("c:\\Python27\\Lib\\site-packages"));
sys.path.append(new PyString("C:\\Python27\\DLLs"));
sys.path.append(new PyString("C:\\Python27\\Lib\\lib-tk"));
sys.path.append(new PyString("C:\\Python27"));
sys.path.append(new PyString("C:\\Python27\\libs"));

I am getting the follwoing error while executing my java code

console: Failed to install '': java.nio.charset.UnsupportedCharsetException: cp0.
Exception in thread "MainThread" Traceback (most recent call last):
  File "tokenextractor.py", line 7, in <module>
    import nltk
  File "c:\Python27\Lib\site-packages\nltk\__init__.py", line 137, in <module>
    from nltk.stem import *
  File "c:\Python27\Lib\site-packages\nltk\stem\__init__.py", line 29, in <module>
    from nltk.stem.snowball import SnowballStemmer
  File "c:\Python27\Lib\site-packages\nltk\stem\snowball.py", line 26, in <module>
    from nltk.corpus import stopwords
  File "c:\Python27\Lib\site-packages\nltk\corpus\__init__.py", line 66, in <module>
    from nltk.corpus.reader import *
  File "c:\Python27\Lib\site-packages\nltk\corpus\reader\__init__.py", line 105, in <module>
    from nltk.corpus.reader.panlex_lite import *
  File "c:\Python27\Lib\site-packages\nltk\corpus\reader\panlex_lite.py", line 15, in <module>
    import sqlite3
  File "c:\Python27\Lib\sqlite3\__init__.py", line 24, in <module>
    from dbapi2 import *
  File "c:\Python27\Lib\sqlite3\dbapi2.py", line 28, in <module>
    from _sqlite3 import *
ImportError: No module named _sqlite3

_sqlite3 is available under Python27/libs, When I executes the python program as a standalone script, it works fine, but while running with Java it gives me this error.