I get an error message when I try FreqDist() in NLTK -- NameError: name 'nltk' is not defined

nltk

Solution

Before you can use FreqDist, you need to import it.

Add a line as follows:

import nltk

or if you just want to use FreqDist you should try this:

>>> from nltk.corpus import brown
>>> from nltk import FreqDist
>>> news_text = brown.words(categories='news')
>>> fdist = FreqDist([w.lower() for w in news_text])

Problem

I'm learning about the NLTK and my mac is working fine except I have trouble with the FreqDist(). (I saw another question about FreqDist() but he was getting a different error message. TypeError: unhashable type: 'list') Here's an example: ``` >>> from nltk.corpus import brown >>> news_text = brown.words(categories='news') >>> fdist = nltk.FreqDist([w.lower() for w in news_text]) Traceback (most recent call last): ` File "<stdin>", line 1, in <module>` `NameError: name 'nltk' is not defined` ``` This error message is pretty consistent. I get this message every time I try the FreqDist(). Other commands like - >>> brown.fileids() are fine. Thanks for your help!

Original source