I'm using nltk for sentiment analysis in a Django project. Every time I run a command with Django's manage.py
, I get this output:
/var/www/example.com/venv-example/lib/python3.5/site-packages/nltk/twitter/__init__.py:20: UserWarning: The twython library has not been installed. Some functionality from the twitter package will not be available.
warnings.warn("The twython library has not been installed. "
I also get emailed by cron since cron emails whenever output is generated. Could this warning just be in the nltk documentation or is it important for it to be in the code too?
Try installing with the twitter
option, e.g.
pip3 install -U nltk[twitter]
Or if you like it fuss-free, all batteries-included:
pip3 install -U nltk[all]
@alvations are you recommending that everyone install with Twitter?
For example, if I just do from nltk.sentiment.vader import SentimentIntensityAnalyzer
, I'll get the error. I don't need any twitter functionality, I'm just getting the warning due to the way things are being imported (some of the Twitter functions seem to be used for demo_
functions in nltk.sentiment.util
).
It's a warning so it's not breaking anything critical. I think it makes sense to install with twitter if you're using nltk.sentiment
, at some point you might need the twython functionalities.
One could also do something like:
export PYTHONWARNINGS="ignore"
$ python
$ from nltk.sentiment.vader import SentimentIntensityAnalyzer
I am also finding this issue quite annoying. We don't want to install with the twitter option as our application will fairly likely never need it and we like to keep our docker images as slim as possible. We also don't want to turn off warnings as that might hide genuine issues from other modules.
It seems like the cause of this is json2csv_preprocess
in nltk/sentiment/util.py
, which in turn seems to only be used in the demos in that file. Perhaps a new demos.py
file could be created, localising the dependency on the twitter option to that one file? That might represent a breaking API change depending on how you define the public API (I couldn't find information on this or where to find information in the CONTRIBUTING.md).
I'm happy to do the work if that solution is acceptable?
I am also finding this issue quite annoying. We don't want to install with the twitter option as our application will fairly likely never need it and we like to keep our docker images as slim as possible. We also don't want to turn off warnings as that might hide genuine issues from other modules.
I completely agree with this.
Proposed fix: https://github.com/nltk/nltk/pull/2175
Most helpful comment
I am also finding this issue quite annoying. We don't want to install with the twitter option as our application will fairly likely never need it and we like to keep our docker images as slim as possible. We also don't want to turn off warnings as that might hide genuine issues from other modules.
It seems like the cause of this is
json2csv_preprocess
innltk/sentiment/util.py
, which in turn seems to only be used in the demos in that file. Perhaps a newdemos.py
file could be created, localising the dependency on the twitter option to that one file? That might represent a breaking API change depending on how you define the public API (I couldn't find information on this or where to find information in the CONTRIBUTING.md).I'm happy to do the work if that solution is acceptable?