Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import matplotlib failing with No module named _tkinter on heroku

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?

like image 572
alpaca Avatar asked Dec 25 '16 06:12

alpaca


1 Answers

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 :-)

like image 168
Ahmed Haque Avatar answered Oct 11 '22 18:10

Ahmed Haque