Differences between revisions 1 and 18 (spanning 17 versions)
Revision 1 as of 2004-05-19 18:09:52
Size: 1342
Editor: 206
Comment:
Revision 18 as of 2006-02-28 06:20:09
Size: 2716
Editor: h-66-134-92-2
Comment: Updated for newer versions of matplotlib
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
= Changes required to matplotlib =
I had to patch matplotlib's __init__.py file in the get_data_path() routine. Specifically, right before raising the error at the end, I added the following code
{{{
#!python
      # CODE ADDED TO SUPPORT PY2EXE
      if sys.frozen:
         path = os.path.join(os.path.split(sys.path[0])[0], 'matplotlib')
         return path
}}}
[http://matplotlib.sf.net MatPlotLib] is a module to produce nice-looking plots in Python using a wide variety of back-end packages, at least one of which is likely to be available for your system. This ability to do things in a generic fashion makes this a simple system to use, but it gets complicated if you wish to distribute an executable instead of scripts. This page describes what I had to do to make matplotlib work with py2exe.
Line 12: Line 5:
We also need to make sure we get the matplotlib subdirectory created in the distribution. This is where we'll include all of the stuff matplotlib includes in the pythonXX\share\matplotlib directory. This is also where the __init__ file has been updated to look for this information.
Line 18: Line 10:
# We need to exclude matplotlib backends not being used by this executable.
# You may find that you need different excludes to create a working executable with your chosen backend
# We need to exclude matplotlib backends not being used by this executable.  You may find
# that you need different excludes to create a working executable with your chosen backend.
# We also need to include matplotlib.numerix.random_array
Line 21: Line 14:
    'py2exe': { 'excludes': ['_gtkagg', '_tkagg'],     'py2exe': { 'includes': 'matplotlib.numerix.random_array',
               
'excludes': ['_gtkagg', '_tkagg'],
Line 23: Line 17:
                                 'libgobject-2.0-0.dll']}                                  'libgobject-2.0-0.dll']
              }
       }

# Additional data files are required by matplotlib. Note that the glob.glob routine
# doesn't seem to pick up the .matplotlib resource file, so I copy that separately.
# Do the same if you need to
setup(
    data_files = [(r'matplotlibdata', glob.glob(r'c:\python24\share\matplotlib\*')),
                  (r'matplotlibdata', [r'c:\python24\share\matplotlib\.matplotlibrc'])],
    name = 'demo',
    description = 'MatPlotLib Demo Program',
    console = ['demo.py']
    )
}}}

= Copying PyTZ folder =
Now copy pytz folder from C:\Python24\Lib\site-packages to your dist/ folder and you're done!


= Update for newer versions of matplotlib =
Recent versions of matplotlib (this is tested with 0.87) have changed the location where data files are found. Here is a sample setup.py that works with simple matplotlib samples. It produces massive distributions - more work needs to be done on how to exclude unused backends.

{{{
#!python
from distutils.core import setup
import py2exe

from distutils.filelist import findall
import os
import matplotlib
matplotlibdatadir = matplotlib.get_data_path()
matplotlibdata = findall(matplotlibdatadir)
matplotlibdata_files = []
for f in matplotlibdata:
    dirname = os.path.join('matplotlibdata', f[len(matplotlibdatadir)+1:])
    matplotlibdata_files.append((os.path.split(dirname)[0], [f]))
Line 26: Line 57:
    # Additional data files required by matplotlib. Note that the glob.glob routine doesn't seem to pick up the .matplotlib resource file     console=['test.py'],
    options={
             'py2exe': {
                        'packages' : ['matplotlib', 'pytz'],
                       }
            },
    data_files=matplotlibdata_files
)

Introduction

[http://matplotlib.sf.net MatPlotLib] is a module to produce nice-looking plots in Python using a wide variety of back-end packages, at least one of which is likely to be available for your system. This ability to do things in a generic fashion makes this a simple system to use, but it gets complicated if you wish to distribute an executable instead of scripts. This page describes what I had to do to make matplotlib work with py2exe.

Special content for setup.py to use matplotlib

   1 # We need to import the glob module to search for all files.
   2 import glob
   3 
   4 # We need to exclude matplotlib backends not being used by this executable.  You may find
   5 # that you need different excludes to create a working executable with your chosen backend.
   6 # We also need to include matplotlib.numerix.random_array
   7 opts = {
   8     'py2exe': { 'includes': 'matplotlib.numerix.random_array',
   9                 'excludes': ['_gtkagg', '_tkagg'],
  10                 'dll_excludes': ['libgdk-win32-2.0-0.dll',
  11                                  'libgobject-2.0-0.dll']
  12               }
  13        }
  14 
  15 # Additional data files are required by matplotlib.  Note that the glob.glob routine
  16 # doesn't seem to pick up the .matplotlib resource file, so I copy that separately.
  17 # Do the same if you need to
  18 setup(
  19     data_files = [(r'matplotlibdata', glob.glob(r'c:\python24\share\matplotlib\*')),
  20                   (r'matplotlibdata', [r'c:\python24\share\matplotlib\.matplotlibrc'])],
  21     name = 'demo',
  22     description = 'MatPlotLib Demo Program',
  23     console = ['demo.py']
  24     )

Copying PyTZ folder

Now copy pytz folder from C:\Python24\Lib\site-packages to your dist/ folder and you're done!

Update for newer versions of matplotlib

Recent versions of matplotlib (this is tested with 0.87) have changed the location where data files are found. Here is a sample setup.py that works with simple matplotlib samples. It produces massive distributions - more work needs to be done on how to exclude unused backends.

   1 from distutils.core import setup
   2 import py2exe
   3 
   4 from distutils.filelist import findall
   5 import os
   6 import matplotlib
   7 matplotlibdatadir = matplotlib.get_data_path()
   8 matplotlibdata = findall(matplotlibdatadir)
   9 matplotlibdata_files = []
  10 for f in matplotlibdata:
  11     dirname = os.path.join('matplotlibdata', f[len(matplotlibdatadir)+1:])
  12     matplotlibdata_files.append((os.path.split(dirname)[0], [f]))
  13 
  14 
  15 setup(
  16     console=['test.py'],
  17     options={
  18              'py2exe': {
  19                         'packages' : ['matplotlib', 'pytz'],
  20                        }
  21             },
  22     data_files=matplotlibdata_files
  23 )

MatPlotLib (last edited 2018-10-31 15:57:34 by JimmyRetzlaff)