Skip to main content
  1. About
  2. For Teams
Asked
Viewed 1k times
1

I have installed ngram using pip install ngram. While I am running the following code

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

I get the error ImportError: cannot import name NGram

Screenshot for it: screenshot of console window

P.S. A similar question has been asked previously using ngram in python, but that time the person who was getting error did not install ngram, so installing ngram worked. In my case I am getting the error in spite of ngram being installed.

2 Answers 2

1

Your Python script is named ngram.py, so it defines a module named ngram. When Python runs from ngram import NGram, Python ends up looking in your script for something named NGram, not in the ngram module you have installed.

Try changing the name of your script to something else, for example ngram_test.py.

Sign up to request clarification or add additional context in comments.

Comments

0

try like this:

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

Comments

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.