I’m on a mac, and I wanted to make a program to define a list of words for me. To this end I installed NLTK with following the instrctions at the official website for Mac/Unix machines. The numpy install failed, not sure if that affects anything. But anyways, working off some sample code from here I made a little simple program
from nltk.corpus import wordnet
print(wordnet)
word = raw_input("Words to define? \n")
for word in word.split():
for synset in wordnet.synsets(word):
print("lexical type:", synset.lexname)
print ("Definition:", synset.definition)
The first time I did this, I got an error, and to fix it I ran the following code in python prompt
import nltk
nltk.download()
I installed almost all the packages (the one that didnt I dont think was relevant) and I ran the above code again. The problem is now I’m getting this error
Traceback (most recent call last):
File "/Users/pipsqueaker/Documents/workspace/wordDefine/main/main.py", line 10, in <module>
for synset in wordnet.synsets(word):
File "/Library/Python/2.7/site-packages/nltk/corpus/util.py", line 68, in __getattr__
self.__load()
File "/Library/Python/2.7/site-packages/nltk/corpus/util.py", line 56, in __load
except LookupError: raise e
LookupError:
**********************************************************************
Resource 'corpora/wordnet' not found. Please use the NLTK
Downloader to obtain the resource: >>> nltk.download()
Searched in:
- '/Users/pipsqueaker/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
**********************************************************************
I installed my nltk to the /usr/share/nltk_data directory, and I navigated to it in finder to make sure it was there, and it was. I’m using osx’s default python with grammar version of 2.7 in Eclipse’s pydev. Do you have any idea what could be causing the problem?
Also, I don’t think its an import error. I can do
import nltk
print(nltk) #this runs nice
What can I do to fix this?
I think this could be due to path issues. I work recommend using virtual envs and pip as standard when working with packages.
Some great notes here: https://python-guide.readthedocs.org/en/latest/
You also might want to try reinstalling even if your not sure it’s ‘relevant’. The error message maybe a general data not found one.