Nltk: Remove the "twython library has not been installed" warning?

Created on 29 Jun 2018  ·  6Comments  ·  Source: nltk/nltk

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?

installation twitter

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 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?

All 6 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jeryini picture jeryini  ·  5Comments

stevenbird picture stevenbird  ·  4Comments

alvations picture alvations  ·  4Comments

libingnan54321 picture libingnan54321  ·  3Comments

peterbe picture peterbe  ·  5Comments