Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name sentiment #8

Closed
jatkins23 opened this issue May 9, 2016 · 29 comments
Closed

ImportError: cannot import name sentiment #8

jatkins23 opened this issue May 9, 2016 · 29 comments

Comments

@jatkins23
Copy link

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
Copy link

mp31415 commented May 9, 2016

In the example there is an alternative way to import:

from vaderSentiment.vaderSentiment import sentiment as vaderSentiment

Would it help?

@jatkins23
Copy link
Author

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
#8 (comment)

Jon Atkins
BS Computer Science
Tufts University 2016

@mp31415
Copy link

mp31415 commented May 17, 2016

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
Copy link

cvint13 commented Dec 9, 2016

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
Copy link
Owner

cjhutto commented Dec 13, 2016

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.

@cjhutto cjhutto closed this as completed Dec 13, 2016
@simonanez
Copy link

@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
Copy link
Owner

cjhutto commented Dec 16, 2016

(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
Copy link

@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
Copy link
Owner

cjhutto commented Dec 21, 2016

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
Copy link

harika5 commented Apr 5, 2017

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
Copy link
Owner

cjhutto commented Apr 11, 2017

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
Copy link

jyayoub commented May 13, 2019

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
Copy link

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
Copy link

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

@cjhutto
Copy link
Owner

cjhutto commented May 11, 2020

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
Copy link

hardiksakhuja commented May 11, 2020

`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
Copy link
Owner

cjhutto commented May 11, 2020

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
Copy link

hardiksakhuja commented May 11, 2020

@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
Copy link
Owner

cjhutto commented May 11, 2020

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
Copy link

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
Copy link

Raunak24x7 commented Jan 28, 2021 via email

@yelizkilinc
Copy link

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
Copy link

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
Copy link

Raunak24x7 commented Jan 29, 2021 via email

@kirch-47
Copy link

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
Copy link

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)

@yelizkilinc

@Raunak24x7
Copy link

Raunak24x7 commented Feb 19, 2021 via email

@tuvshuug
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests