16

I want to import wordnet dictionary but when i import Dictionary form wordnet i see this error :

 for l in open(WNSEARCHDIR+'/lexnames').readlines():
IOError: [Errno 2] No such file or directory: 'C:\\Program Files\\WordNet\\2.0\\dict/lexnames'

I install wordnet2.1 in this directory but i cant import please help me to solve this problem

import nltk
from nltk import *
from nltk.corpus import wordnet
from wordnet import Dictionary

print '-----------------------------------------'
print Dictionary.length
Fred Foo
  • 355,277
  • 75
  • 744
  • 836
Masoud Abasian
  • 10,549
  • 6
  • 23
  • 22

2 Answers2

30

The following works for me:

>>> nltk.download()
# Download window opens, fetch wordnet
>>> from nltk.corpus import wordnet as wn

Now I've a WordNetCorpusReader called wn. I don't know why you're looking for a Dictionary class, since there's no such class listed in the docs. The NLTK book, in section 2.5, explains what you can do with the nltk.corpus.wordnet module.

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
  • The version from @alvas worked for me using Jupyter notebook, python 3.5. `ntlk.download()` alone cannot open a GUI from inside a notebook. It sure would be nice if the help for this command did a better job of listing the correct strings to use for all the options. – szeitlin Aug 15 '16 at 17:16
  • Maybe there has been an update, but calling `ntlk.download()` in Jupyter opens the GUI on my Win10 computer. (Jupyter is running on localhost, and not on a remote host.) – Thomas Fauskanger Jun 14 '17 at 14:28
  • Solved my problem. – alyssaeliyah Nov 21 '19 at 14:33
7

You should try these commands:

import nltk
nltk.download('wordnet')

It worked for me.

Malik Hamza
  • 181
  • 1
  • 10