gpt4 book ai didi

python - 在 python 中导入 ngram 时出错

转载 作者:太空宇宙 更新时间:2023-11-03 15:16:48 25 4
gpt4 key购买 nike

我已经使用 pip install ngram 安装了 ngram。当我运行以下代码时

from ngram import NGram
c=NGram.compare('cereal_crop','cereals')
print c

我收到错误ImportError:无法导入名称 NGram

屏幕截图:screenshot of console window

附注以前曾提出过类似的问题using ngram in python ,但是当时出现错误的人没有安装 ngram,所以安装 ngram 有效。就我而言,尽管安装了 ngram,我还是收到错误。

最佳答案

您的 Python 脚本名为 ngram.py,因此它定义了一个名为 ngram 的模块。当 Python 运行 from ngram import NGram 时,Python 最终会在脚本中查找名为 NGram 的内容,而不是在已安装的 ngram 模块中查找。

尝试将脚本名称更改为其他名称,例如 ngram_test.py

关于python - 在 python 中导入 ngram 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43819092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com