在Python中使用ngram

0 投票
1 回答
2427 浏览
提问于 2025-04-17 07:45

我正在尝试运行以下代码

       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。

撰写回答