Differences between revisions 8 and 10 (spanning 2 versions)
Revision 8 as of 2004-11-17 19:14:04
Size: 2112
Editor: www
Comment:
Revision 10 as of 2005-07-03 21:09:32
Size: 3059
Editor: dsl-082-083-155-193
Comment: Reflect current packages (__init__.py already patched)
Deletions are marked like this. Additions are marked like this.
Line 5: Line 5:
''As with version 0.82, this change is already in upstream source and no longer needed. Just include the special setup.py code below, and you should be fine'' -- Ferry Dave 07-03-2005
Line 12: Line 14:
}}}

MichaelTwomey - I had to patch the patch above to handle sys.path a bit differently. With the above patch and my py2exe's behaviour instead of getting something like c:\apps\myapp\matplotlibdata, I was getting c:\apps\matplotlibdata as the data path. So I've used the following instead:

{{{
if sys.platform=='win32' and sys.frozen:
    path = os.path.join(sys.path[0], 'matplotlibdata')
    return path
}}}

As a workaround to support both methods:

{{{
if sys.platform=='win32' and sys.frozen:
    path = os.path.join(os.path.split(sys.path[0])[0], 'matplotlibdata')
    if not os.path.isdir(path):
        # Try again assuming sys.path[0] is a dir not a exe
        path = os.path.join(sys.path[0], 'matplotlibdata')
    return path

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.

Changes required to matplotlib

As with version 0.82, this change is already in upstream source and no longer needed. Just include the special setup.py code below, and you should be fine -- Ferry Dave 07-03-2005

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

   1       # CODE ADDED TO SUPPORT PY2EXE
   2       if sys.frozen:
   3          path = os.path.join(os.path.split(sys.path[0])[0], 'matplotlib')
   4          return path

MichaelTwomey - I had to patch the patch above to handle sys.path a bit differently. With the above patch and my py2exe's behaviour instead of getting something like c:\apps\myapp\matplotlibdata, I was getting c:\apps\matplotlibdata as the data path. So I've used the following instead:

if sys.platform=='win32' and sys.frozen:
    path = os.path.join(sys.path[0], 'matplotlibdata')
    return path

As a workaround to support both methods:

if sys.platform=='win32' and sys.frozen:
    path = os.path.join(os.path.split(sys.path[0])[0], 'matplotlibdata')
    if not os.path.isdir(path):
        # Try again assuming sys.path[0] is a dir not a exe
        path = os.path.join(sys.path[0], 'matplotlibdata')
    return path

Special content for setup.py to use matplotlib

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.

   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 opts = {
   7     'py2exe': { 'excludes': ['_gtkagg', '_tkagg'],
   8                 'dll_excludes': ['libgdk-win32-2.0-0.dll',
   9                                  'libgobject-2.0-0.dll']
  10               }
  11        }
  12 
  13 # Additional data files are required by matplotlib.  Note that the glob.glob routine
  14 # doesn't seem to pick up the .matplotlib resource file, so I copy that separately.
  15 setup(
  16     data_files = [('matplotlib', glob.glob(r'c:\python23\share\matplotlib\*')),
  17                   ('matplotlib', [r'c:\python23\share\matplotlib\.matplotlibrc'])],
  18     name = 'demo',
  19     description = 'MatPlotLib Demo Program',
  20     console = ['demo.py']
  21     )

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