Michael Ryan
Michael Ryan

Reputation: 73

How to fix 'encoding' issue in Python using vaderSentiment package

I am working on a sentiment analysis problem and found the vaderSentiment package but cannot get it to run. It is giving me an 'encoding' error.

I have tried adding 'from io import open' but that did not fix my issue. Please see code below.

from io import open
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

analyser = SentimentIntensityAnalyzer()

def sentiment_analyzer_scores(sentence):
    score = analyser.polarity_scores(sentence)
    print("{:-<40} {}".format(sentence, str(score)))

sentiment_analyzer_scores("The phone is super cool.") 

Here are the results I am wanting:

"The phone is super cool----------------- {'neg': 0.0, 'neu': 0.326, 'pos':         
0.674, 'compound': 0.7351}"

The results I am getting:

File "<ipython-input-27-bbb91818db04>", line 6, in <module>
analyser = SentimentIntensityAnalyzer()

File "C:\Users\mr110e\AppData\Local\Continuum\anaconda2\lib\site
packages\vaderSentiment\vaderSentiment.py", line 212, in __init__
with open(lexicon_full_filepath, encoding='utf-8') as f:

TypeError: 'encoding' is an invalid keyword argument for this function

Upvotes: 0

Views: 752

Answers (2)

Budi Santoso
Budi Santoso

Reputation: 1

Open this file using a text editor

<your python2 instalation path>\lib\site-packages\vaderSentiment\vaderSentiment.py

Add these lines on the top of file:

from io import open
#------------------
import os
import re
import math
import string
import requests
import json
from itertools import product
from inspect import getsourcefile

Upvotes: 0

Artemij Rodionov
Artemij Rodionov

Reputation: 1826

The vaderSentiment package doesn't support python 2.

You should use python 3 or little bit edit the package's source code

Upvotes: 1

Related Questions