ami*_*its 2 python installation nlp porter-stemmer nltk
我正在我的项目中导入 nltk 库,但出现以下错误。如果有人有同样的错误,请帮助。
Traceback (most recent call last):
File "/home/nitai/Dropbox/thesis/PycharmProjects/auto_tagger2/tagger.py", line 4, in <module>
import buildVocab
File "/home/nitai/Dropbox/thesis/PycharmProjects/auto_tagger2/buildVocab.py", line 4, in <module>
import nltk
File "/usr/local/lib/python2.7/dist-packages/nltk/__init__.py", line 126, in <module>
from nltk.stem import *
File "/usr/local/lib/python2.7/dist-packages/nltk/stem/__init__.py", line 29, in <module>
from nltk.stem.snowball import SnowballStemmer
File "/usr/local/lib/python2.7/dist-packages/nltk/stem/snowball.py", line 25, in <module>
from nltk.stem import porter
ImportError: cannot import name porter
Run Code Online (Sandbox Code Playgroud)
我已经安装了所有 nltk 软件包。我不知道。
如果您已经从NLTK下载了所有数据包,即
>>> import nltk
>>> nltk.download('all')
Run Code Online (Sandbox Code Playgroud)
NLTK 中的 Porter Stemmer 是一个类,而不是一个包/模块。
您应该导入 PorterStemmer 类:
>>> from nltk.stem import PorterStemmer
>>> porter = PorterStemmer()
>>> porter.stem('went')
u'went'
>>> porter.stem('running')
u'run'
Run Code Online (Sandbox Code Playgroud)
另外,请通过安装来检查您是否拥有最新稳定版本的 NLTK pip。否则,您可能使用的是不稳定/过时的 NLTK 版本。请参阅http://www.nltk.org/install.html