[英]Import Error in NLTK: Cannot import name compat
I am using 'nltk' installed by pip in my project.我在我的项目中使用 pip 安装的“nltk”。 It works fine in local But when I tried to deploy in google appengine , It shows the Import error 'Cannot import name compat'.它在本地工作正常但是当我尝试在 google appengine 中部署时,它显示导入错误“无法导入名称兼容”。 How to resolve it?如何解决? Thanks in advance提前致谢
update: the code更新:代码
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
The error错误
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
Try and upgrading your ntlk package:尝试升级您的 ntlk 包:
pip install --upgrade nltk
fixed this problem in my case在我的情况下解决了这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.