在Python中使用ngram
我正在尝试运行以下代码
from ngram import NGram
NGram.compare('foo', 'foobar')
但是我遇到了这个错误
Traceback (most recent call last):
File "E:/pt/tandra", line 1, in <module>
from ngram import Ngram
ImportError: No module named ngram
可能是什么原因呢?ngram文件夹和这个文件在同一个目录下。
1 个回答
2
你没有名为 ngram 的模块。你需要先安装它。
只需使用
easy_install ngram
或者
pip install ngram
在终端中输入(适用于 Linux、Mac OS 和 Windows 的 Cygwin),前提是你已经安装了 Python 的 setuptools。