nltk StanfordNERTagger : NoClassDefFoundError: org/slf4j/LoggerFactory (In Windows)

后端 未结 9 2087
轮回少年
轮回少年 2020-12-15 09:43

NOTE: I am using Python 2.7 as part of Anaconda distribution. I hope this is not a problem for nltk 3.1.

I am trying to use nltk for NER as

import nl         


        
9条回答
  •  被撕碎了的回忆
    2020-12-15 10:36

    i fixed!

    u should indicate the full path of slf4j-api.jar in CLASSPATH

    instead of add jar-path into system environment variable, u can do like this in code:

    _CLASS_PATH = "."    
    if os.environ.get('CLASSPATH') is not None:
        _CLASS_PATH = os.environ.get('CLASSPATH')
    os.environ['CLASSPATH'] = _CLASS_PATH + ';F:\Python\Lib\slf4j\slf4j-api-1.7.13.jar'
    

    important, in nltk/*/stanford.py will reset the classpath like this:

    stdout, stderr = java(cmd, classpath=self._stanford_jar, stdout=PIPE, stderr=PIPE)
    

    eg. \Python34\Lib\site-packages\nltk\tokenize\stanford.py line:90

    u can fix it like this:

    _CLASS_PATH = "."
    if os.environ.get('CLASSPATH') is not None:
        _CLASS_PATH = os.environ.get('CLASSPATH')
    stdout, stderr = java(cmd, classpath=(self._stanford_jar, _CLASS_PATH), stdout=PIPE, stderr=PIPE)
    

提交回复
热议问题