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

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

Closed
esitharth opened this issue Jul 12, 2018 · 5 comments
Closed

Comments

@esitharth
Copy link

Im getting this error while compiling SentimentIntensityAnalyzer()

ErrorLog:
venv/local/lib/python2.7/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

@cjhutto
Copy link
Owner

cjhutto commented Jul 12, 2018

try adding this to your list of imports to make it backward compatible for Python 2.7:

from io import open

@esitharth
Copy link
Author

Thank you for your quick response. Did that. Worked like a charm.

@Kprzeorski
Copy link

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
from io import open
analyzer = SentimentIntensityAnalyzer()

ERROR:

TypeErrorTraceback (most recent call last)
<ipython-input-8-c96d329cbe73> in <module>()
      1 from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
      2 from io import open
----> 3 analyzer = SentimentIntensityAnalyzer()

/home/kap/anaconda3/envs/py36/lib/python2.7/site-packages/vaderSentiment/vaderSentiment.pyc in 
__init__(self, lexicon_file, emoji_lexicon)
    210         _this_module_file_path_ = os.path.abspath(getsourcefile(lambda: 0))
    211         lexicon_full_filepath = os.path.join(os.path.dirname(_this_module_file_path_), lexicon_file)
--> 212         with open(lexicon_full_filepath, encoding='utf-8') as f:
    213             self.lexicon_full_filepath = f.read()
    214         self.lexicon = self.make_lex_dict()

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

I tried running the 3 line code inside a Jupyter notebook with python 3.6 and outside of jupyter in a terminal within python 2.7 and produced the same error. I used Ubuntu OS. Maybe put 'from io import open' in the vaderSentiment.py file? I would need instructions to produce complied bytecode to overwrite the existing one..... I've never done that before. Any suggestions or solutions?

jakebiesinger added a commit to jakebiesinger/vaderSentiment that referenced this issue Aug 9, 2018
@sunit1409
Copy link

sunit1409 commented Sep 5, 2019

sudo nano /home/kap/anaconda3/envs/py36/lib/python2.7/site-packages/vaderSentiment/vaderSentiment.py

put from io import open in this file not on yours

@rxng
Copy link

rxng commented Oct 15, 2019

I am facing this issue as well.

from io import open

This gets rid of the message

with open(lexicon_full_filepath, encoding='utf-8') as f:

But then now the error is showing for

File "/usr/local/lib/python2.7/dist-packages/vaderSentiment/vaderSentiment.py", line 212, in init
lexicon_full_filepath = os.path.join(os.path.dirname(this_module_file_path), lexicon_file)
TypeError: 'encoding' is an invalid keyword argument for this function

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

5 participants