NLTK中的导入错误:无法导入名称兼容

时间:2018-10-25 08:15:12

标签: python nlp

我在项目中使用的是pip安装的“ nltk”。它在本地工作正常,但是当我尝试在google appengine中进行部署时,它显示了导入错误“无法导入名称兼容性”。怎么解决呢?预先感谢

更新:代码

from nltk import word_tokenize, pos_tag, ne_chunk, tree2conlltags

sentence = "Hi , This week has been crazy. My report is on IBM. Can you give it a quick read and provide some feedback. She is in London. John  lives in New   York  and works for the European Union."

ne_tree = ne_chunk(pos_tag(word_tokenize(sentence)))
iob_tagged = tree2conlltags(ne_tree)
print iob_tagged
name = []
for chunk in iob_tagged:
    if chunk[2] != 'O':
        name.append(chunk[2])
    else:
        name.append(chunk[0])
print name

错误

from nltk.corpus import wordnet, words
File "/base/data/home/apps/s~/prod-2582.413469289899104484/lib/nltk/__init__.py", line 137, in <module>
from nltk.stem import *
File "/base/data/home/apps/s~/prod-2582.413469289899104484/lib/nltk/stem/__init__.py", line 29, in <module>
from nltk.stem.snowball import SnowballStemmer
File "/base/data/home/apps/s~/prod-2582.413469289899104484/lib/nltk/stem/snowball.py", line 31, in <module>
from nltk import compat
ImportError: cannot import name compat

1 个答案:

答案 0 :(得分:0)

尝试并升级您的ntlk软件包:

pip install --upgrade nltk

解决了我的情况