I'm trying to use matplotlib
in my application. I created a virtualenv in python2.7, pip installed matplotlib, and it's successfully running on local.
However, when I deploy the app to heroku
(after pip freeze
and other steps necessary), my app crashes. When I check the log, I see the following:
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
It's weird because the app was successfully running on local under venv. Is the heroku python environment not configured to run matplotlib
? If so, what steps should I take to enable that?
This should do the trick
matplotlib.use('Agg')
import matplotlib.pyplot as plt
This will set your Matplotlib backend to use Agg instead of Tk. Just worked for me at least :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With