Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

py2exe `ImportError: No module named backend_tkagg`

I am trying to make a windows executable from a python script that uses matplotlib and it seems that I am getting a common error.

File "run.py", line 29, in import matplotlib.pyplot as plt File "matplotlib\pyplot.pyc", line 95, in File "matplotlib\backends__init__.pyc", line 25, in pylab_setup ImportError: No module named backend_tkagg

The problem is that I didn't found a solution while googling all over the internet.

Here is my setup.py

from distutils.core import setup
import matplotlib
import py2exe 
matplotlib.use('TkAgg')
setup(data_files=matplotlib.get_py2exe_datafiles(),console=['run.py'])
like image 846
kechap Avatar asked Jan 06 '12 22:01

kechap


1 Answers

First, the easy question, is that backend installed? On my Fedora system I had to install it separately from the base matplotlib.

At a Python console can you:

>>> import matplotlib.backends.backend_tkagg

If that works, then force py2exe to include it. In your config:

opts = {
  'py2exe': { "includes" : ["matplotlib.backends.backend_tkagg"] }
}
like image 78
Mark Avatar answered Sep 20 '22 12:09

Mark