Shawn Driscoll's Tech Blog

Stuff That Happened in the Past

Wednesday, February 5, 2014

Getting Py2exe to Work With Matplotlib for Python 2.5

I just started playing around with Matplotlib in Python 2.5.4. I love it so far. And, of course, I just had to make a Windows EXE file from a project I was working on. Nothing but crashes using Py2exe until I learned about glob.

The problem I was having was with the Matplotlib data files not being included/found when running the EXE. At the CMD prompt, I enter py2exe as usual.

The code is below:

# Used successfully in Python 2.5.4 for py2exe and matplotlib
from distutils.core import setup
import py2exe

import glob
opts = {'py2exe': {'includes': ['matplotlib.backends',
                                'matplotlib.figure', 'pylab', 'numpy',
                   'excludes': ['_gtkagg', '_tkagg', '_agg2', '_cairo', '_cocoaagg',
                                '_fltkagg', '_gtk', '_gtkcairo'],
                   'dll_excludes': ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll']

data_files = [(r'mpl-data', glob.glob(r'C:\Python25\Lib\site-packages\matplotlib\mpl-data\*.*')),
                  (r'mpl-data', [r'C:\Python25\Lib\site-packages\matplotlib\mpl-data\matplotlibrc']),
                  (r'mpl-data\images', glob.glob(r'C:\Python25\Lib\site-packages\matplotlib\mpl-data\images\*.*')),
                  (r'mpl-data\fonts', glob.glob(r'C:\Python25\Lib\site-packages\matplotlib\mpl-data\fonts\*.*'))]

# for console program use "console = [{'script': ''}]"
# for windows program use "windows = [{'script': '3d6_line_bar.pyw'}]"
setup(windows = [{'script': '3d6_line_bar.pyw'}], options=opts, data_files=data_files)

No comments:

Post a Comment