9

I am a beginner at Python and am trying to use nltk.sentiment.vader but get a recurrent error message despite multiple attempts to fix it. I previously installed most of NTLK (3 modules were out of date so couldn't install them). I then installed nltk.sentiment.vader using the command line prompt and my output was "Successfully installed vaderSentiment-2.5". "vaderSentiment in c:\anaconda\lib\site-packages". I then run the script below and repeatedly get the error message below:

from nltk.sentiment.vader import SentimentIntensityAnalyzer
sid = SentimentIntensityAnalyzer()
ss = sid.polarity_scores(sentence_that_I want_to_analyze)  
print(ss)

output:

LookupError:


Resource 'sentiment/vader_lexicon.zip/vader_lexicon/vader_lexicon.txt' not found. Please use the NLTK Downloader to obtain the resource: >>> nltk.download() Searched in: - 'C:\Users\name/nltk_data' - 'C:\nltk_data' - 'D:\nltk_data' - 'E:\nltk_data' - 'C:\Anaconda\nltk_data' - 'C:\Anaconda\lib\nltk_data' - 'C:\Users\name\AppData\Roaming\nltk_data' - ''


I noticed that the error message doesn't include the location where the package was installed =c:\anaconda\lib\site-packages. Is this the reason that I am getting this error? How do I fix this?

Thank you very much for the help

4
  • the error is stated : you don't have the source data it needs. Are you sure you have it? Did you download sources after you installed NLTK? It has its own GUI installer to download these sources and it seems that it can't find the files where they should be Commented Apr 21, 2017 at 15:34
  • Thank you for the help. I am not sure what you mean by did I download sources after I downloaded NTLK ? I downloaded ntlk by nltk.download() then I selected all. After this I installed vader as above. Am I missing a step? Commented Apr 21, 2017 at 15:42
  • regardless of NLTK and python, do you have vader_lexicon.txt on your computer? If not you should go again through the download step and make sure to download the package without error. I'm not sure what's happening but the error is pretty clear : you just don't have the file (at the right location?) Commented Apr 21, 2017 at 15:44
  • Thank you for the help. I re downloaded nltk it using the code from this post and it now works:stackoverflow.com/questions/27658409/… Commented Apr 21, 2017 at 16:17

3 Answers 3

23
import nltk
nltk.downloader.download('vader_lexicon')

instead of 'vader_lexicon',put your desired package

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

Comments

8

You have to install it from NLTK's installer. If you're like me, you figured it out, but you still don't know the package's name.

Follow these steps:

python > import nltk > nltk.download() > d > vader_lexicon

That should do it. If d isn't recognized try Download.

enter image description here

2 Comments

nltk.download() seems to open a GUI now but the dataset still has the same name!
@GarethD Doesn't happen to me even though I have the latest version installed (I tried both with python 2.7 and 3.6).
0

It doesn't seems to find the 'vader' resource, as this line states:

Resource 'sentiment/vader_lexicon.zip/vader_lexicon/vader_lexicon.txt' not found. 
Please use the NLTK Downloader to obtain the resource:

So, you will need to download Vader Lexicon by heading to the command prompt with activated venv

(venv) PS ~location~> py
Python 3.12.5 (tags/v3.12.5:ff3bc82, Aug  6 2024, 20:45:27) [MSC v.1940 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>> nltk.download()
showing info https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/index.xml

It will open a window named NLTK Downloader. If you can't see it, go to your taskbar and click on this logo: The NLTK Downloader on the taskbar

Go ahead and click on all packages

All Packages

Scroll downwards until you find 'vader_lexicon'

Vader Lexicon

In the image below, you will find:

  • I - Select the vader_lexicon package by dragging on it from left to right (Blue)
  • II - Click the download button
  • III - If the package is already downloaded, it will show this message or if you are downloading the package for the first time it will show here:

Finished downloading 'vader_lexicon'.

Downloading package

Now you can go ahead and close the window and type in your python file, importing nltk.sentiment.vader

Note -- When you close the NLTK Downloader window, the console will output True

Comments

Your Answer

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.