cjhutto / vaderSentiment

VADER Sentiment Analysis. VADER (Valence Aware Dictionary and sEntiment Reasoner) is a lexicon and rule-based sentiment analysis tool that is specifically attuned to sentiments expressed in social media, and works well on texts from other domains.
MIT License
4.45k stars 1k forks source link

ImportError: cannot import name sentiment #8

Closed jatkins23 closed 7 years ago

jatkins23 commented 8 years ago

I installed vaderSentiment with pip and have ensured it is in the correct file, un- and re-installed it, attempted to upgrade pip, attempted to change the permissions for the files and am still having difficulty using this library. Error below:

Traceback (most recent call last): File "search_twitter.py", line 1, in from vaderSentiment import sentiment as vaderSentiment ImportError: cannot import name sentiment

Any help as soon as possible would be greatly appreciated as my project is due on Tuesday. Thank you very much, Jon

mp31415 commented 8 years ago

In the example there is an alternative way to import:

from vaderSentiment.vaderSentiment import sentiment as vaderSentiment

Would it help?

jatkins23 commented 8 years ago

Yes, that helped, thank you. Apologies for the unnecessary issue. Though I was still unable to link it via pip install, cloning the repository is fine for my scale of app.

Any advice on how to change/add to the dictionary? Basically, I am analyzing political tweets from the past week and am trying to add links (to popular memes from that time that have a sentiment) and in particular just to add the word "nazi," by copying and pasting the syntax and values from the word ni***r. I have tried everything, including just replacing the string "nazi" with the its sentiment equivalent word before calling vaderSentiment(), but that doesn't work either. I'm sure its an issue on my part, but would love any help if you don't mind. Thank you!

Jon

On Mon, May 9, 2016 at 4:00 PM, mp31415 notifications@github.com wrote:

In the example there is an alternative way to import:

from vaderSentiment.vaderSentiment import sentiment as vaderSentiment

Would it help?

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/cjhutto/vaderSentiment/issues/8#issuecomment-217972142

Jon Atkins BS Computer Science Tufts University 2016

mp31415 commented 8 years ago

I didn't try to modify the dictionary, but I don't see why "nazi" would be any different from any other entry in the dictionary. I did notice though that on non-Windows platform encoding of the dictionary must be changed to UTF-8 and some invalid entries must be fixed (see one of the recent issues).

I also noticed that dictionary file may be put next to your python file (in the same folder), because vader first tries to open it there and only if it fails falls back to the original file in the vader package.

cvint13 commented 7 years ago

When I tried both possible ways to import listed above, I got the following error:

File "/usr/anaconda3/lib/python3.5/site-packages/vaderSentiment/vaderSentiment.py", line 23 return dict(map(lambda (w, m): (w, float(m)), [wmsr.strip().split('\t')[0:2] for wmsr in open(f) ])) ^ SyntaxError: invalid syntax

Is this a python 3 issue or something?

cjhutto commented 7 years ago

Thanks! The new update (with new pip install) has better compatibility support for Python 3 to address cvint13's issue, and helps with the encoding/decoding issues. The lexicon dictionary file has been encoded with UTF-8 unicode by default (I hope) for better cross-os performance. I've implemented code to automatically detect where the dictionary file is installed (as long as you didn't change it's location relative to where the actual "vaderSentiment.py" file got installed), so no longer any need to manually put a copy of the dictionary file next to your python file (in the same folder)... from what I can tell, my implementation should work across OSs.

simonanez commented 7 years ago

@cjhutto Before i imported using: "from vaderSentiment.vaderSentiment import sentiment as vaderSentiment" on python 2.7 Now with the new pip install i get: ImportError: cannot import name sentiment What's the new way to import and the new method to run sentiment analysis?

cjhutto commented 7 years ago

(Note: this upgrade uses Python 3x)

after you've run $ pip install --upgrade vaderSentiment

try this in your python terminal or IDE:

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyzer = SentimentIntensityAnalyzer()
vs = analyzer.polarity_scores("this is a good example")
print(str(vs))
print(str(vs["compound"]))
simonanez commented 7 years ago

@cjhutto What are the instructions to install the previous version? I've been doing a project that's due in a few days, i tried on a different computer with the new version to run sentiment analysis on 400k tweets and it's been taking over 30 minutes (still going) whether as before it just took 2-3 minutes max

cjhutto commented 7 years ago

You can always use pip uninstall vaderSentiment Then use the typical commands to install a particular version, for example: pip install vaderSentiment==versionyouwant or even: pip install vaderSentiment<2.0

harika5 commented 7 years ago

I am still getting the same error even after trying both the import options. I am using python 3.5 and vaderSentiment version is 2.5

from vaderSentiment import sentiment as vaderSentiment ImportError: cannot import name 'sentiment'

Does anyone have any solution to this??

cjhutto commented 7 years ago

Hi @harika5, It looks like you're trying to use the new version of VADER with an older version of the import code snippet...

As seen in the updated code examples on the first page of the VADER GitHub, your import should look like this:

    from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
    #note: depending on how you installed (e.g., using source code download versus pip install), you may need to import like this:
    #from vaderSentiment import SentimentIntensityAnalyzer

then you should be able to run your text though the analyzer like this:

analyzer = SentimentIntensityAnalyzer()
vs = analyzer.polarity_scores("this is a good example")
print(str(vs))
print(str(vs["compound"]))
jyayoub commented 5 years ago

hi, I was able to download vaderSentiment, but each time I try to import it from python using this from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer, I recieve this error:

import vaderSentiment Traceback (most recent call last): File "<pyshell#21>", line 1, in import vaderSentiment ModuleNotFoundError: No module named 'vaderSentiment'

Raunak24x7 commented 4 years ago

ModuleNotFoundError Traceback (most recent call last)

in 5 import pandas as pd 6 import numpy as np ----> 7 from vaderSentiment.vaderSentiment import sentiment as vaderSentiment 8 from wordcloud import WordCloud 9 import nltk ModuleNotFoundError: No module named 'vaderSentiment'
hardiksakhuja commented 4 years ago

@Raunak24x7 i am getting the same error . Have you been able to fix it yet ?

cjhutto commented 4 years ago

Have you looked at the code examples provided on the VADER GitHub homepage? I think your solution is already provided there...

for example, see the new import method:

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

hardiksakhuja commented 4 years ago

`from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

analyzer = SentimentIntensityAnalyzer()`

File ".\vaderSentiment.py", line 4, in from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer File "E:\Final Project\vaderSentiment.py", line 4, in from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer ModuleNotFoundError: No module named 'vaderSentiment.vaderSentiment'; 'vaderSentiment' is not a package

I have used vaderSentiment recently like a month back and it worked like a charm . i went back to my code to do some more digging and now it shows me this . 1 month back this exact thing was working just fine .

PS - i have uninstalled the package too . Reinstalled it again . and that didnt help me too

cjhutto commented 4 years ago

Not sure what to tell you -- I'm not able to reproduce your error. I just tested it with a fresh install on a new virtual environment, and then ran the example code shown on the homepage. It all worked with no errors at all.

vader

hardiksakhuja commented 4 years ago

@cjhutto Okay , I fixed the problem . I still dont know what was it exactly. But i thought the cached image must have something wrong with it or I came upon this discussion where the package may not get fetched for python version you are using python -m pip install vaderSentiment --no-cache-dir instead of just "pip install vaderSentiment" This did the trick. It all works fine now !!!

cjhutto commented 4 years ago

Oh good! python -m pip install vaderSentiment --no-cache-dir is a great thing to keep in mind ... maybe this will help others as well.
Thanks for adding the note!

yelizkilinc commented 3 years ago

I have read all of them but any of them did not work for me. I am using tabPy on Tableau. I am getting: 'ModuleNotFoundError : No module named 'vaderSentiment'' error. I can see that module exists on C:\Python39\Lib\site-packages\vaderSentiment. My python version is 3.9.1 I hope you have an idea?

Raunak24x7 commented 3 years ago

Thank you for the clarification

On Thu, Jan 28, 2021 at 4:02 PM yelizkilinc notifications@github.com wrote:

I have read all of them but any of them did not work for me. I am using tabPy on Tableau. I am getting: 'ModuleNotFoundError : No module named 'vaderSentiment'' error. I can see that module exists on C:\Python39\Lib\site-packages\vaderSentiment. My python version is 3.9.1 I hope you have an idea?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cjhutto/vaderSentiment/issues/8#issuecomment-769144468, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF3MT4VPB3HT5CXIRUD2UT3S4F37JANCNFSM4CDHEBDQ .

--

Best Regards, Raunak Mishra Contact Number :(+91)-8750324627

yelizkilinc commented 3 years ago

I solved the above issue. TabPy was looking to another path, not Python folder. I copied files to correct path. But this time, init.py file is empty. And I am getting ImportError : cannot import name 'SentimentIntensityAnalyzer' from 'vaderSentiment' (c:\anaconda3\lib\site-packages\vaderSentiment__init__.py) error. I wrote by myself, but it did not accept.

yelizkilinc commented 3 years ago

Please do not try to solve. I solved it, it can be done without init.py. I came at the beginning and your suggestions above worked. Thanks

Raunak24x7 commented 3 years ago

Ok, thanks.

On Thu, Jan 28, 2021 at 5:10 PM yelizkilinc notifications@github.com wrote:

Please do not try to solve. I solved it, it can be done without init.py. I came at the beginning and your suggestions above worked. Thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cjhutto/vaderSentiment/issues/8#issuecomment-769192913, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF3MT4VQLA43B3CTRY7HFKLS4GD7JANCNFSM4CDHEBDQ .

--

Best Regards, Raunak Mishra Contact Number :(+91)-8750324627

kirch-47 commented 3 years ago

Please do not try to solve. I solved it, it can be done without init.py. I came at the beginning and your suggestions above worked. Thanks

So how did you fix it? As I am getting this error as well: ImportError: cannot import name 'SentimentIntensityAnalyzer' from 'vaderSentiment' (c:\Users\Aiden\OneDrive\Documents\WsB workspace VS.venv\lib\site-packages\vaderSentiment__init__.py)

kirch-47 commented 3 years ago

Please do not try to solve. I solved it, it can be done without init.py. I came at the beginning and your suggestions above worked. Thanks

So how did you fix it? As I am getting this error as well: ImportError: cannot import name 'SentimentIntensityAnalyzer' from 'vaderSentiment' (c:\Users\Aiden\OneDrive\Documents\WsB workspace VS.venv\lib\site-packages\vaderSentimentinit.py)

@yelizkilinc

Raunak24x7 commented 3 years ago

Ok, I'll check it out.

On Fri, Feb 19, 2021 at 10:07 PM kirch-47 notifications@github.com wrote:

Please do not try to solve. I solved it, it can be done without init.py. I came at the beginning and your suggestions above worked. Thanks

So how did you fix it? As I am getting this error as well: ImportError: cannot import name 'SentimentIntensityAnalyzer' from 'vaderSentiment' (c:\Users\Aiden\OneDrive\Documents\WsB workspace VS.venv\lib\site-packages\vaderSentimentinit.py)

@yelizkilinc https://github.com/yelizkilinc

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cjhutto/vaderSentiment/issues/8#issuecomment-782352301, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF3MT4XSWH45A7PNRPCVGELS73HI5ANCNFSM4CDHEBDQ .

--

Best Regards, Raunak Mishra Contact Number :(+91)-8750324627

tuvshuug commented 2 years ago

I had the same problems. The resolution is I deleted the git cloned vadersentiment folder. then I did

  1. pip uninstall vaderSentiment
  2. python -m pip install vaderSentiment --no-cache-dir
  3. or pip install --upgrade vaderSentiment

Good luck guys

Shyam2214 commented 6 months ago

Trying to install sentiments for my web app that work on python flaks i pip install sentiments but when I run code it shows module name sentiments not found