matplotlib, py2exe import problems

Can someone tell me how to successfully create an executable

    > of a script that uses matplotlib? The example script in the
    > documentation does not appear to work for my case. I keep
    > missing modules, and everytime I add the missing module, a
    > new one crops up. Much like the problems listed here:
    > http://mail.python.org/pipermail/python-list/2005-February/267595.html
    > My recent error message is:

    > Traceback (most recent call last):

    > File "Uranium_Leaching_ Modelv1.py", line 162, in ?

    > File "pylab.pyc", line 1, in ?

    > File "matplotlib\pylab.pyc", line 217, in ?

    > File "matplotlib\backends\__init__.pyc", line 24, in
    > pylab_setup

    > ImportError: No module named backend_tkagg

Which backend do you want to use? Are you using the pylab interface.
It looks like you are getting the default win32 backend backend_tkagg
but you have explicitly excluded it with

    "py2exe": {"excludes": ['_gtkagg', '_tkagg'],

It looks like you are using an old example, because these lines are
not included in the examples pointed to in the FAQ. BTW, I have just
tested and updated the py2exe example zip file so you may want
download it

  http://matplotlib.sourceforge.net/faq.html#PY2EXE
  http://matplotlib.sourceforge.net/py2exe_examples.zip

The update includes an example for tkagg in addition to gtkagg and
wxagg.

Note in the current release in matplotlib (0.83.1), before freezing,
you need to replace these lines in
site-packages/matplotlib/numerix/__init__.py

g = globals()
l = locals()
__import__('ma', g, l)
__import__('fft', g, l)
__import__('linear_algebra', g, l)
__import__('random_array', g, l)
__import__('mlab', g, l)

la = linear_algebra
ra = random_array

with the following

from matplotlib import FROZEN

if not FROZEN:
    g = globals()
    l = locals()
    __import__('ma', g, l)
    __import__('fft', g, l)
    __import__('linear_algebra', g, l)
    __import__('random_array', g, l)
    __import__('mlab', g, l)

    la = linear_algebra
    ra = random_array

because they break py2exe. These lines import the sub-modules of
numerix (fft, ma, mlab, etc) into the numerix namespace. So you can
do for example

import numerix as nx
x = nx.mlab.mean( nx.mlab.randn(10000)

w/o them you have to explicitly import the submodules. Can anyone
suggest a way to do this that doesn't break py2exe? Apparently py2exe
doesn't handle __import__ very well.

JDH

Hi John,

John Hunter wrote:

"Noko" == Noko Phala <nphala@...681...> writes:

    > Can someone tell me how to successfully create an executable
    > of a script that uses matplotlib? The example script in the
    > documentation does not appear to work for my case. I keep
    > missing modules, and everytime I add the missing module, a
    > new one crops up. Much like the problems listed here:
    > http://mail.python.org/pipermail/python-list/2005-February/267595.html
    > My recent error message is:

    > Traceback (most recent call last):

    > File "Uranium_Leaching_ Modelv1.py", line 162, in ?

    > File "pylab.pyc", line 1, in ?

    > File "matplotlib\pylab.pyc", line 217, in ?

    > File "matplotlib\backends\__init__.pyc", line 24, in
    > pylab_setup

    > ImportError: No module named backend_tkagg

Which backend do you want to use? Are you using the pylab interface.
It looks like you are getting the default win32 backend backend_tkagg
but you have explicitly excluded it with

    "py2exe": {"excludes": ['_gtkagg', '_tkagg'],

It looks like you are using an old example, because these lines are
not included in the examples pointed to in the FAQ. BTW, I have just
tested and updated the py2exe example zip file so you may want
download it

  http://matplotlib.sourceforge.net/faq.html#PY2EXE
  http://matplotlib.sourceforge.net/py2exe_examples.zip

The update includes an example for tkagg in addition to gtkagg and
wxagg.

Note in the current release in matplotlib (0.83.1), before freezing,
you need to replace these lines in
site-packages/matplotlib/numerix/__init__.py

g = globals()
l = locals()
__import__('ma', g, l)
__import__('fft', g, l)
__import__('linear_algebra', g, l)
__import__('random_array', g, l)
__import__('mlab', g, l)

la = linear_algebra
ra = random_array

with the following

from matplotlib import FROZEN

if not FROZEN:
    g = globals()
    l = locals()
    __import__('ma', g, l)
    __import__('fft', g, l)
    __import__('linear_algebra', g, l)
    __import__('random_array', g, l)
    __import__('mlab', g, l)

    la = linear_algebra
    ra = random_array

because they break py2exe. These lines import the sub-modules of
numerix (fft, ma, mlab, etc) into the numerix namespace. So you can
do for example

import numerix as nx
x = nx.mlab.mean( nx.mlab.randn(10000)

w/o them you have to explicitly import the submodules. Can anyone
suggest a way to do this that doesn't break py2exe? Apparently py2exe
doesn't handle __import__ very well.

I just added "matplotlib.numerix" to the packages line as follows.

"packages": ["encodings", "kinterbasdb", "pytz", "matplotlib.numerix"],

See you
Werner

···

JDH

-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click