Matplotlib + py2exe = frustration

I cross-posted this on py2exe-users w/o getting help yet.

Yes, I've read the Wiki - http://starship.python.net/crew/theller/moin.cgi/MatPlotLib
and any other pages I could google. I want to package a pylab (aka scipy, aka matplotlib) app. I'm on Win XP. I've been trying for four days. I've boiled it down to this:

···

-----------------------------------------------------
Test.py:
import pylab
a = arange(10)
print a

-----------------------------------------------------
Setup.py:
from distutils.core import setup
import py2exe
import glob

# from py2exe wiki: matplotlib
"""
These don't work so I commented them out:
opts = {
    'py2exe': { 'excludes': ['_gtkagg', '_tkagg'],
                'dll_excludes': ['libgdk-win32-2.0-0.dll',
                                 'libgobject-2.0-0.dll'],
                'includes': ['matplotlib.numerix.random_array'],
              }
       }
"""

setup(
    # This doesn't make it work either:
    data_files = [
                  (r'lib\matplotlibdata', glob.glob(r'c:\python23\share\matplotlib\*')),
                  (r'lib\matplotlibdata', glob.glob(r'c:\Python23\share\matplotlib\.matplotlibrc')),
                  ],
    version = "0.7.0",
    description = "test py2exe & pylab",
    name = "TestPy2exe",
    author = "Michael E Huster",
    # targets to build
    console = ["test.py"]

    )
-----------------------------------------------------
I run:

python setup.py py2exe
cd dist
test.exe

Traceback (most recent call last):
  File "test.py", line 1, in ?
  File "pylab.pyc", line 1, in ?
  File "matplotlib\__init__.pyc", line 509, in ?
  File "matplotlib\__init__.pyc", line 245, in wrapper
  File "matplotlib\__init__.pyc", line 318, in _get_data_path
RuntimeError: Could not find the matplotlib data files

Michael Huster, Ph. D.
Assistant Professor of Science
Simpson University
2211 College View Dr.
Redding, CA 96003

Here is a simple setup.py script I am successfully using with the most recent version of mpl. I run py2exe like, "python.exe setup.py py2exe -c -p numarray,pytz".

···

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

for ver in range(2,5):
     if os.path.exists('C:\\Python2%i\\share\\matplotlib\\' % ver):
         data = glob.glob('C:\\Python2%i\\share\\matplotlib\\*' % ver)
         break

setup( windows = ['nlogui.py'],
        data_files = [('', ['nlo.gif']),
                      ('matplotlibdata', data)],
        options={"py2exe":{"optimize":2}},
)
-----------------------------------

Michael Huster wrote:

I cross-posted this on py2exe-users w/o getting help yet.

Yes, I've read the Wiki - http://starship.python.net/crew/theller/moin.cgi/MatPlotLib
and any other pages I could google. I want to package a pylab (aka scipy, aka matplotlib) app. I'm on Win XP. I've been trying for four days. I've boiled it down to this:

-----------------------------------------------------
Test.py:
import pylab
a = arange(10)
print a

-----------------------------------------------------
Setup.py:
from distutils.core import setup
import py2exe
import glob

# from py2exe wiki: matplotlib
"""
These don't work so I commented them out:
opts = {
    'py2exe': { 'excludes': ['_gtkagg', '_tkagg'],
                'dll_excludes': ['libgdk-win32-2.0-0.dll',
                                 'libgobject-2.0-0.dll'],
                'includes': ['matplotlib.numerix.random_array'],
              }
       }
"""

setup(
    # This doesn't make it work either:
    data_files = [
                  (r'lib\matplotlibdata', glob.glob(r'c:\python23\share\matplotlib\*')),
                  (r'lib\matplotlibdata', glob.glob(r'c:\Python23\share\matplotlib\.matplotlibrc')),
                  ],
    version = "0.7.0",
    description = "test py2exe & pylab",
    name = "TestPy2exe",
    author = "Michael E Huster",
    # targets to build
    console = ["test.py"]

    )
-----------------------------------------------------
I run:
> python setup.py py2exe
> cd dist
> test.exe
Traceback (most recent call last):
  File "test.py", line 1, in ?
  File "pylab.pyc", line 1, in ?
  File "matplotlib\__init__.pyc", line 509, in ?
  File "matplotlib\__init__.pyc", line 245, in wrapper
  File "matplotlib\__init__.pyc", line 318, in _get_data_path
RuntimeError: Could not find the matplotlib data files

>

Michael Huster, Ph. D.
Assistant Professor of Science
Simpson University
2211 College View Dr.
Redding, CA 96003

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hi Michael,

Me again.

What version of matplotlib are you using?

I attached a test.py, test2.py (which is like yours except the import is corrected) and a setup.py.

Change in setup.py this

script = "test.py"

to

script = "test2.py"

I can generate both of them and run them on Win XP either as a windows or console app, however test2.py looks as if nothing happens as it only prints some stuff.

Note that the exe will be under dist/prog.

I based this setup.py on mine and removed all my stuff, however left a bit more in then is the absolute minimum (e.g. pytz is only needed if you do some date stuff etc etc).

Also you need to remove the Python24 stuff.

Hope this helps to get you going.

See you
Werner

Michael Huster wrote:

test2.py (46 Bytes)

test.py (950 Bytes)

setup.py (2.91 KB)

···

I cross-posted this on py2exe-users w/o getting help yet.

Yes, I've read the Wiki - http://starship.python.net/crew/theller/moin.cgi/MatPlotLib
and any other pages I could google. I want to package a pylab (aka scipy, aka matplotlib) app. I'm on Win XP. I've been trying for four days. I've boiled it down to this:

-----------------------------------------------------
Test.py:
import pylab
a = arange(10)
print a

-----------------------------------------------------
Setup.py:
from distutils.core import setup
import py2exe
import glob

# from py2exe wiki: matplotlib
"""
These don't work so I commented them out:
opts = {
    'py2exe': { 'excludes': ['_gtkagg', '_tkagg'],
                'dll_excludes': ['libgdk-win32-2.0-0.dll',
                                 'libgobject-2.0-0.dll'],
                'includes': ['matplotlib.numerix.random_array'],
              }
       }
"""

setup(
    # This doesn't make it work either:
    data_files = [
                  (r'lib\matplotlibdata', glob.glob(r'c:\python23\share\matplotlib\*')),
                  (r'lib\matplotlibdata', glob.glob(r'c:\Python23\share\matplotlib\.matplotlibrc')),
                  ],
    version = "0.7.0",
    description = "test py2exe & pylab",
    name = "TestPy2exe",
    author = "Michael E Huster",
    # targets to build
    console = ["test.py"]

    )
-----------------------------------------------------
I run:
> python setup.py py2exe
> cd dist
> test.exe
Traceback (most recent call last):
  File "test.py", line 1, in ?
  File "pylab.pyc", line 1, in ?
  File "matplotlib\__init__.pyc", line 509, in ?
  File "matplotlib\__init__.pyc", line 245, in wrapper
  File "matplotlib\__init__.pyc", line 318, in _get_data_path
RuntimeError: Could not find the matplotlib data files

>

Michael Huster, Ph. D.
Assistant Professor of Science
Simpson University
2211 College View Dr.
Redding, CA 96003

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf