matplotlib py2exe problem

Please be kind....poor starving newbie. I've seen this

    > question posted around but can't seem to find an answer:
    > does anybody have experience creating an .exe for a
    > matplotlib program using py2exe?

    > My testMPL.py application is all set to go, but when I run
    > py2exe with the suggested setup.py file, I get
    > errors. (I'm using ActiveState Python 2.4.2 Build 10)

Daniel, just for our information: are you using the py2exe examples
from the matplotlib FAQ page? I think these are probably a bit out of
date as of the 0.86 release because of the way we recently reorganized
the package data (fonts, thumbnails etc).

Charlie, have you tested any of the new egg / package organization
stuff with py2exe?

JDH

I just tried with an old project that I used py2exe with and it does
look like we still need the py2exe specific check in get_data_path
since py2exe zips the pure python code into a library.zip. I updated
my setup.py file for that old project and I am pasting it below. In
my specific case I was using numarray (numpy didn't exist), so now I
have to exclude numpy or errors occur for some unknown reason. I just
added the old py2exe check to get_data_path and everything worked
fine. I will add this to cvs.

Until the next release you can just uncomment the following lines in
matplotlib/__init__.py#_get_data_path():
    if sys.platform=='win32' and sys.frozen:
        path = os.path.join(os.path.split(sys.path[0])[0], 'matplotlibdata')
        if os.path.isdir(path): return path
        else:
            # Try again assuming sys.path[0] is a dir not a exe
            path = os.path.join(sys.path[0], 'matplotlibdata')
            if os.path.isdir(path): return path

Begin setup.py script

···

On 2/7/06, John Hunter <jdhunter@...4...> wrote:

    > Please be kind....poor starving newbie. I've seen this
    > question posted around but can't seem to find an answer:
    > does anybody have experience creating an .exe for a
    > matplotlib program using py2exe?

    > My testMPL.py application is all set to go, but when I run
    > py2exe with the suggested setup.py file, I get
    > errors. (I'm using ActiveState Python 2.4.2 Build 10)

Daniel, just for our information: are you using the py2exe examples
from the matplotlib FAQ page? I think these are probably a bit out of
date as of the 0.86 release because of the way we recently reorganized
the package data (fonts, thumbnails etc).

Charlie, have you tested any of the new egg / package organization
stuff with py2exe?

--------------------------------------------------------------------------------------
# For py2exe only
"""
Run with the following command (use py2exe 0.6.2 or higher)

   python.exe -OO setup.py py2exe -b 3 -c -p numarray,pytz -e numpy
"""

import os
from distutils.core import setup
import py2exe
import glob

import matplotlib
mplfiles = glob.glob(os.sep.join([matplotlib.get_data_path(), '*']))
# Need to explicitly remove cocoa_agg nib folder or py2exe complains
mplfiles.remove(os.sep.join([matplotlib.get_data_path(), 'Matplotlib.nib']))

setup( version = '0.9.1',
       windows = ['nlogui.py'],
       data_files = [('', ['nlo.gif', '../vtkrotate/NMA.pdb']),
                     ('matplotlibdata', mplfiles)],
       options={"py2exe":{"optimize":2}},
)

I just committed the changes to cvs and added a convenience function
for py2exe called get_py2exe_datafiles. The script I pasted before
now looks like this:

Begin setup.py script

···

--------------------------------------------------------------------------------------
# For py2exe only
"""
Run with the following command (use py2exe 0.6.2 or higher)

   python.exe -OO setup.py py2exe -b 3 -c -p numarray,pytz -e numpy
"""

import os
from distutils.core import setup
import py2exe
import glob

import matplotlib

setup( version = '0.9.1',
       windows = ['nlogui.py'],
       data_files = [('', ['nlo.gif', '../vtkrotate/NMA.pdb']),
                     matplotlib.get_py2exe_datafiles()],
       options={"py2exe":{"optimize":2}},
)