9

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'])
kechap
  • 2,077
  • 6
  • 28
  • 50

4 Answers4

5

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"] }
}
Mark
  • 106,305
  • 20
  • 172
  • 230
  • `import matplotlib.backends.backend_tkagg` works and I added the option but the problem remains – kechap Jan 07 '12 at 01:04
2

If you are using py2exe it doesn't handle .egg formatted Python modules. If you used easy_install to install the trouble module then you might only have the .egg version. See the py2exe site for more info on how to fix it.

http://www.py2exe.org/index.cgi/ExeWithEggs

Pete
  • 21
  • 1
0

This works well

from distutils.core import setup import py2exe, sys, os import matplotlib

sys.setrecursionlimit(12000) sys.argv.append('py2exe')

setup( options = { "py2exe" : { "bundle_files":3, "compressed":True, "includes" : ["matplotlib.backends.backend_tkagg"] } }, windows = [{"script": "script.py"}],

zipfile = None,

data_files=matplotlib data_files = matplotlib.get_py2exe_datafiles(), )

cesarpro
  • 1
  • 1
0

Run the following command to install the backend_tkagg

For centos -- sudo yum install python-matplotlib-tk

This should work.

shreyas-agrawal
  • 244
  • 2
  • 5