如何使用 vaderSentiment 包修复 Python 中的 'encoding' 问题
How to fix 'encoding' issue in Python using vaderSentiment package
我正在处理情绪分析问题并找到了 vaderSentiment 包,但无法将其发送到 运行。它给我一个 'encoding' 错误。
我试过添加 'from io import open' 但这并没有解决我的问题。请看下面的代码。
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.")
这是我想要的结果:
"The phone is super cool----------------- {'neg': 0.0, 'neu': 0.326, 'pos':
0.674, 'compound': 0.7351}"
我得到的结果:
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
vaderSentiment
软件包不支持 python 2.
使用文本编辑器打开此文件
<your python2 instalation path>\lib\site-packages\vaderSentiment\vaderSentiment.py
在文件顶部添加这些行:
from io import open
#------------------
import os
import re
import math
import string
import requests
import json
from itertools import product
from inspect import getsourcefile
我正在处理情绪分析问题并找到了 vaderSentiment 包,但无法将其发送到 运行。它给我一个 'encoding' 错误。
我试过添加 'from io import open' 但这并没有解决我的问题。请看下面的代码。
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.")
这是我想要的结果:
"The phone is super cool----------------- {'neg': 0.0, 'neu': 0.326, 'pos':
0.674, 'compound': 0.7351}"
我得到的结果:
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
vaderSentiment
软件包不支持 python 2.
使用文本编辑器打开此文件
<your python2 instalation path>\lib\site-packages\vaderSentiment\vaderSentiment.py
在文件顶部添加这些行:
from io import open
#------------------
import os
import re
import math
import string
import requests
import json
from itertools import product
from inspect import getsourcefile