我已经安装了ngram使用pip安装ngram。当我运行以下代码时
from ngram import NGram
c=NGram.compare('cereal_crop','cereals')
print c
我得到了错误ImportError: cannot import name NGram
截图:
在此之前,using ngram in python曾问过一个类似的问题,但那次出错的人没有安装ngram,所以安装ngram是有效的。在我的例子中,尽管ngram正在安装,但我还是会得到错误。
发布于 2017-05-06 10:37:05
您的Python脚本名为ngram.py
,因此它定义了一个名为ngram
的模块。当Python运行from ngram import NGram
时,Python最终会在脚本中查找名为NGram
的内容,而不是您已经安装的ngram
模块。
尝试将脚本的名称更改为其他内容,例如ngram_test.py
。
发布于 2017-05-06 10:06:41
就像这样:
import ngram
c = ngram.NGram.compare('cereal_crop','cereals')
print c
https://stackoverflow.com/questions/43819092
复制相似问题