Can't run matplotlib without "tk" backend on windows?

Hi, after having correctly compiled matplotlib, now is time to test
something (I need at least to get it something working before I can
start hack it autonomously =). Unfortunately, it's not usable: it
complains about not being able to load "_tkagg" module. The fact is I
don't want "tkagg" backend at all! Here is the backends dependencies
detect log:

OPTIONAL BACKEND DEPENDENCIES
                libpng: found, but unknown version (no pkg-config)
               Tkinter: no
                        * Tkinter present, but header files are not found.
                        * You may need to install development packages.
              wxPython: no
                        * wxPython not found
                  Gtk+: gtk+: 2.10.11, glib: 2.12.11, pygtk: 2.10.6,
                        pygobject: 2.12.3
                    Qt: no
                   Qt4: no
                 Cairo: 1.2.6

As it should be clear, I want to use the a gtk+ aware backend, and
initially in fact I used a customized "setup.cfg"; seeing the error I
tryed deleting the customized "setup.cfg", but without results. Is
there some problems with backend selection on windows platform?
I hope gtk+ backends are supported. Follows 2 traces of the error
running an ipython shell and a test python program (it works on
linux).

Any help is appreciated.

Thanks,
Francesco

···

---------------------------------------------------------------------------

Here is the trace in ipython trying to run sample test program:

In [3]: run lab1_ex2.py

ImportError Traceback (most recent call last)

C:\Documents and Settings\Public\desktop\lab1_ex2.py in <module>()
      1 from numpy import *
      2 from scipy import *
----> 3 from pylab import *
      4
      5 n=100

c:\python25\Lib\site-packages\pylab.py in <module>()
----> 1
      2
      3 from matplotlib.pylab import *
      4 import matplotlib.pylab
      5 __doc__ = matplotlib.pylab.__doc__

c:\python25\Lib\site-packages\matplotlib\pylab.py in <module>()
    290
    291
--> 292 from matplotlib.pyplot import *
    293
    294

c:\python25\Lib\site-packages\matplotlib\pyplot.py in <module>()
     35
     36 from matplotlib.backends import pylab_setup
---> 37 new_figure_manager, draw_if_interactive, show = pylab_setup()
     38
     39 def switch_backend(newbackend):

c:\python25\Lib\site-packages\matplotlib\backends\__init__.py in pylab_setup()
     22 backend_name = 'backend_'+backend.lower()
     23 backend_mod = __import__('matplotlib.backends.'+backend_name,
---> 24 globals(),locals(),[backend_name])
     25
     26 # Things we pull in from all backends

c:\python25\Lib\site-packages\matplotlib\backends\backend_tkagg.py in <module>()

      6
      7 import Tkinter as Tk, FileDialog
----> 8 import tkagg # Paint image to Tk photo blitter extension

      9 from backend_agg import FigureCanvasAgg
     10

c:\python25\Lib\site-packages\matplotlib\backends\tkagg.py in <module>()
----> 1
      2
      3 import _tkagg
      4 import Tkinter as Tk
      5
      6 def blit(photoimage, aggimage, bbox=None, colormode=1):
      7 tk = photoimage.tk

ImportError: No module named _tkagg
WARNING: Failure executing file: <lab1_ex2.py>

---------------------------------------------------------------------------

Here is another trace trying to run ipython with "--pylab" switch:

Traceback (most recent call last):
  File "C:\Python25\scripts\ipython", line 27, in <module>
    IPython.Shell.start().mainloop()
  File "C:\Python25\lib\site-packages\IPython\Shell.py", line 1152, in start
    return shell(user_ns = user_ns)
  File "C:\Python25\lib\site-packages\IPython\Shell.py", line 1049, in __init__
    shell_class=MatplotlibShell)
  File "C:\Python25\lib\site-packages\IPython\Shell.py", line 74, in __init__
    debug=debug,shell_class=shell_class)
  File "C:\Python25\Lib\site-packages\IPython\ipmaker.py", line 95, in make_IPyt
hon
    embedded=embedded,**kw)
  File "C:\Python25\lib\site-packages\IPython\Shell.py", line 589, in __init__
    user_ns,b2 = self._matplotlib_config(name,user_ns)
  File "C:\Python25\lib\site-packages\IPython\Shell.py", line 530, in _matplotli
b_config
    import matplotlib.pylab as pylab
  File "c:\python25\Lib\site-packages\matplotlib\pylab.py", line 292, in <module

    from matplotlib.pyplot import *
  File "c:\python25\Lib\site-packages\matplotlib\pyplot.py", line 37, in <module

    new_figure_manager, draw_if_interactive, show = pylab_setup()
  File "c:\python25\Lib\site-packages\matplotlib\backends\__init__.py", line 24,
in pylab_setup
    globals(),locals(),[backend_name])
  File "c:\python25\Lib\site-packages\matplotlib\backends\backend_tkagg.py", lin
e 8, in <module>
    import tkagg # Paint image to Tk photo blitter extension
  File "c:\python25\Lib\site-packages\matplotlib\backends\tkagg.py", line 1, in
<module>
    import _tkagg
ImportError: No module named _tkagg

You need to set a different backend in your matplotlibrc or specify it first.

import matplotlib
matplotlib.use('Agg')

You can also run scripts passing the backend:

python lab1_ex2.py -dAgg

···

On Jan 9, 2008 8:41 AM, Francesco Pretto <ceztkoml@...287...> wrote:

Hi, after having correctly compiled matplotlib, now is time to test
something (I need at least to get it something working before I can
start hack it autonomously =). Unfortunately, it's not usable: it
complains about not being able to load "_tkagg" module. The fact is I
don't want "tkagg" backend at all! Here is the backends dependencies
detect log:

OPTIONAL BACKEND DEPENDENCIES
                libpng: found, but unknown version (no pkg-config)
               Tkinter: no
                        * Tkinter present, but header files are not found.
                        * You may need to install development packages.
              wxPython: no
                        * wxPython not found
                  Gtk+: gtk+: 2.10.11, glib: 2.12.11, pygtk: 2.10.6,
                        pygobject: 2.12.3
                    Qt: no
                   Qt4: no
                 Cairo: 1.2.6

As it should be clear, I want to use the a gtk+ aware backend, and
initially in fact I used a customized "setup.cfg"; seeing the error I
tryed deleting the customized "setup.cfg", but without results. Is
there some problems with backend selection on windows platform?
I hope gtk+ backends are supported. Follows 2 traces of the error
running an ipython shell and a test python program (it works on
linux).

Any help is appreciated.

Thanks,
Francesco

---------------------------------------------------------------------------

Here is the trace in ipython trying to run sample test program:

In [3]: run lab1_ex2.py

ImportError Traceback (most recent call last)

C:\Documents and Settings\Public\desktop\lab1_ex2.py in <module>()
      1 from numpy import *
      2 from scipy import *
----> 3 from pylab import *
      4
      5 n=100

c:\python25\Lib\site-packages\pylab.py in <module>()
----> 1
      2
      3 from matplotlib.pylab import *
      4 import matplotlib.pylab
      5 __doc__ = matplotlib.pylab.__doc__

c:\python25\Lib\site-packages\matplotlib\pylab.py in <module>()
    290
    291
--> 292 from matplotlib.pyplot import *
    293
    294

c:\python25\Lib\site-packages\matplotlib\pyplot.py in <module>()
     35
     36 from matplotlib.backends import pylab_setup
---> 37 new_figure_manager, draw_if_interactive, show = pylab_setup()
     38
     39 def switch_backend(newbackend):

c:\python25\Lib\site-packages\matplotlib\backends\__init__.py in pylab_setup()
     22 backend_name = 'backend_'+backend.lower()
     23 backend_mod = __import__('matplotlib.backends.'+backend_name,
---> 24 globals(),locals(),[backend_name])
     25
     26 # Things we pull in from all backends

c:\python25\Lib\site-packages\matplotlib\backends\backend_tkagg.py in <module>()

      6
      7 import Tkinter as Tk, FileDialog
----> 8 import tkagg # Paint image to Tk photo blitter extension

      9 from backend_agg import FigureCanvasAgg
     10

c:\python25\Lib\site-packages\matplotlib\backends\tkagg.py in <module>()
----> 1
      2
      3 import _tkagg
      4 import Tkinter as Tk
      5
      6 def blit(photoimage, aggimage, bbox=None, colormode=1):
      7 tk = photoimage.tk

ImportError: No module named _tkagg
WARNING: Failure executing file: <lab1_ex2.py>

---------------------------------------------------------------------------

Here is another trace trying to run ipython with "--pylab" switch:

Traceback (most recent call last):
  File "C:\Python25\scripts\ipython", line 27, in <module>
    IPython.Shell.start().mainloop()
  File "C:\Python25\lib\site-packages\IPython\Shell.py", line 1152, in start
    return shell(user_ns = user_ns)
  File "C:\Python25\lib\site-packages\IPython\Shell.py", line 1049, in __init__
    shell_class=MatplotlibShell)
  File "C:\Python25\lib\site-packages\IPython\Shell.py", line 74, in __init__
    debug=debug,shell_class=shell_class)
  File "C:\Python25\Lib\site-packages\IPython\ipmaker.py", line 95, in make_IPyt
hon
    embedded=embedded,**kw)
  File "C:\Python25\lib\site-packages\IPython\Shell.py", line 589, in __init__
    user_ns,b2 = self._matplotlib_config(name,user_ns)
  File "C:\Python25\lib\site-packages\IPython\Shell.py", line 530, in _matplotli
b_config
    import matplotlib.pylab as pylab
  File "c:\python25\Lib\site-packages\matplotlib\pylab.py", line 292, in <module
>
    from matplotlib.pyplot import *
  File "c:\python25\Lib\site-packages\matplotlib\pyplot.py", line 37, in <module
>
    new_figure_manager, draw_if_interactive, show = pylab_setup()
  File "c:\python25\Lib\site-packages\matplotlib\backends\__init__.py", line 24,
in pylab_setup
    globals(),locals(),[backend_name])
  File "c:\python25\Lib\site-packages\matplotlib\backends\backend_tkagg.py", lin
e 8, in <module>
    import tkagg # Paint image to Tk photo blitter extension
  File "c:\python25\Lib\site-packages\matplotlib\backends\tkagg.py", line 1, in
<module>
    import _tkagg
ImportError: No module named _tkagg

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

2008/1/9, Charlie Moad <cwmoad@...287...>:

You need to set a different backend in your matplotlibrc or specify it first.

import matplotlib
matplotlib.use('Agg')

You can also run scripts passing the backend:

python lab1_ex2.py -dAgg

Oh, thanks. That really seems a RTFM...

However, in linux i hadn't to select the backend, i just configure
"setup.cfg" to exclude backends and, after compiling, matplotlib was
running just fine choosing the right backend (gtk or gtkagg). Isn't
this a sign that matplotlib isn't able to detect the correct default
backend at compile time (at least on windows)?

However, thanks again. As promised, now I'll try to be more autonomous :wink:

Greetins,
Francesco

setup.py attempts to select the appropriate backend for you, based on what
backends were available at build time. That selection is written into the
default matplotlibrc file, which resides in
site-packages/matplotlib/mpl-data. If matplotlib finds another matplotlibrc
file (for example, in the current working directory, in $HOME/.matplotlib,
etc), then it will use those settings instead. I would guess that is the
source of the problem.

Darren

···

On Wednesday 09 January 2008 09:27:39 am Francesco Pretto wrote:

2008/1/9, Charlie Moad <cwmoad@...287...>:
> You need to set a different backend in your matplotlibrc or specify it
> first.
>
> import matplotlib
> matplotlib.use('Agg')
>
> You can also run scripts passing the backend:
>
> python lab1_ex2.py -dAgg

Oh, thanks. That really seems a RTFM...

However, in linux i hadn't to select the backend, i just configure
"setup.cfg" to exclude backends and, after compiling, matplotlib was
running just fine choosing the right backend (gtk or gtkagg). Isn't
this a sign that matplotlib isn't able to detect the correct default
backend at compile time (at least on windows)?

However, thanks again. As promised, now I'll try to be more autonomous :wink:

2008/1/9, Darren Dale <darren.dale@...163...>:

setup.py attempts to select the appropriate backend for you, based on what
backends were available at build time. That selection is written into the
default matplotlibrc file, which resides in
site-packages/matplotlib/mpl-data. If matplotlib finds another matplotlibrc
file (for example, in the current working directory, in $HOME/.matplotlib,
etc), then it will use those settings instead. I would guess that is the
source of the problem.

No, the problem is the default installed matplotlibrc, that is not
different from the one present in the source tree and has the default
selection:

backend : TkAgg

Now, i don't know if the build script is trying to modify it according
user selection or compile-time backend detection, but I'm wondering
why the same problem wasn't happening on linux, where I tipically
never install Tk runtime.

However, for me the problem is solved, but if there's a matplotlib
windows dev listening, here is my experience; first, i removed the
already installed "lib/site-packages/matplotlib/mpl-data/matplotlibrc"
. Afer, I went for clean compiling with a setup.cfg with these
configurations:

gtk = True
gtkagg = False
tkagg = False
wxagg = False
backend = GTK

Eventually, "python setup.py install" write again a
"site-packages/matplotlib/mpl-data/matplotlibrc" which still have:

backend : TkAgg

If this shouldn't happen, well, consider this a bug report :smiley:

Greetings,
Francesco Pretto

Oh, I see. Look at line 238 in setup.py. Maybe we don't need that check for
sys.platform anymore, now that we have setup.cfg. I think that check was in
there for the benefit of building the windows installers, which we wanted to
default to tkagg.

I think it would be best to use a setup.cfg to set the numerix and backends
when building the windows installers. Charlie, does that sound alright?

Darren

···

On Wednesday 09 January 2008 10:15:54 am Francesco Pretto wrote:

2008/1/9, Darren Dale <darren.dale@...163...>:
> setup.py attempts to select the appropriate backend for you, based on
> what backends were available at build time. That selection is written
> into the default matplotlibrc file, which resides in
> site-packages/matplotlib/mpl-data. If matplotlib finds another
> matplotlibrc file (for example, in the current working directory, in
> $HOME/.matplotlib, etc), then it will use those settings instead. I would
> guess that is the source of the problem.

No, the problem is the default installed matplotlibrc, that is not
different from the one present in the source tree and has the default
selection:

backend : TkAgg

Now, i don't know if the build script is trying to modify it according
user selection or compile-time backend detection, but I'm wondering
why the same problem wasn't happening on linux, where I tipically
never install Tk runtime.

However, for me the problem is solved, but if there's a matplotlib
windows dev listening, here is my experience; first, i removed the
already installed "lib/site-packages/matplotlib/mpl-data/matplotlibrc"
. Afer, I went for clean compiling with a setup.cfg with these
configurations:

gtk = True
gtkagg = False
tkagg = False
wxagg = False
backend = GTK

Eventually, "python setup.py install" write again a
"site-packages/matplotlib/mpl-data/matplotlibrc" which still have:

backend : TkAgg

If this shouldn't happen, well, consider this a bug report :smiley:

That's fine. I didn't use setup.cfg for the latest binaries though.

···

On Jan 9, 2008 10:35 AM, Darren Dale <darren.dale@...163...> wrote:

On Wednesday 09 January 2008 10:15:54 am Francesco Pretto wrote:
> 2008/1/9, Darren Dale <darren.dale@...163...>:
> > setup.py attempts to select the appropriate backend for you, based on
> > what backends were available at build time. That selection is written
> > into the default matplotlibrc file, which resides in
> > site-packages/matplotlib/mpl-data. If matplotlib finds another
> > matplotlibrc file (for example, in the current working directory, in
> > $HOME/.matplotlib, etc), then it will use those settings instead. I would
> > guess that is the source of the problem.
>
> No, the problem is the default installed matplotlibrc, that is not
> different from the one present in the source tree and has the default
> selection:
>
> backend : TkAgg
>
> Now, i don't know if the build script is trying to modify it according
> user selection or compile-time backend detection, but I'm wondering
> why the same problem wasn't happening on linux, where I tipically
> never install Tk runtime.
>
> However, for me the problem is solved, but if there's a matplotlib
> windows dev listening, here is my experience; first, i removed the
> already installed "lib/site-packages/matplotlib/mpl-data/matplotlibrc"
> . Afer, I went for clean compiling with a setup.cfg with these
> configurations:
>
> gtk = True
> gtkagg = False
> tkagg = False
> wxagg = False
> backend = GTK
>
> Eventually, "python setup.py install" write again a
> "site-packages/matplotlib/mpl-data/matplotlibrc" which still have:
>
> backend : TkAgg
>
> If this shouldn't happen, well, consider this a bug report :smiley:

Oh, I see. Look at line 238 in setup.py. Maybe we don't need that check for
sys.platform anymore, now that we have setup.cfg. I think that check was in
there for the benefit of building the windows installers, which we wanted to
default to tkagg.

I think it would be best to use a setup.cfg to set the numerix and backends
when building the windows installers. Charlie, does that sound alright?

That is no problem. If you had, the binaries would not be any different than
they are now. I'll make the change tomorrow, and send you the appropriate
setup.cfg for building the windows installer.

Darren

···

On Wednesday 09 January 2008 8:50:46 pm Charlie Moad wrote:

On Jan 9, 2008 10:35 AM, Darren Dale <darren.dale@...163...> wrote:
> On Wednesday 09 January 2008 10:15:54 am Francesco Pretto wrote:
> > 2008/1/9, Darren Dale <darren.dale@...163...>:
> > > setup.py attempts to select the appropriate backend for you, based on
> > > what backends were available at build time. That selection is written
> > > into the default matplotlibrc file, which resides in
> > > site-packages/matplotlib/mpl-data. If matplotlib finds another
> > > matplotlibrc file (for example, in the current working directory, in
> > > $HOME/.matplotlib, etc), then it will use those settings instead. I
> > > would guess that is the source of the problem.
> >
> > No, the problem is the default installed matplotlibrc, that is not
> > different from the one present in the source tree and has the default
> > selection:
> >
> > backend : TkAgg
> >
> > Now, i don't know if the build script is trying to modify it according
> > user selection or compile-time backend detection, but I'm wondering
> > why the same problem wasn't happening on linux, where I tipically
> > never install Tk runtime.
> >
> > However, for me the problem is solved, but if there's a matplotlib
> > windows dev listening, here is my experience; first, i removed the
> > already installed "lib/site-packages/matplotlib/mpl-data/matplotlibrc"
> > . Afer, I went for clean compiling with a setup.cfg with these
> > configurations:
> >
> > gtk = True
> > gtkagg = False
> > tkagg = False
> > wxagg = False
> > backend = GTK
> >
> > Eventually, "python setup.py install" write again a
> > "site-packages/matplotlib/mpl-data/matplotlibrc" which still have:
> >
> > backend : TkAgg
> >
> > If this shouldn't happen, well, consider this a bug report :smiley:
>
> Oh, I see. Look at line 238 in setup.py. Maybe we don't need that check
> for sys.platform anymore, now that we have setup.cfg. I think that check
> was in there for the benefit of building the windows installers, which we
> wanted to default to tkagg.
>
> I think it would be best to use a setup.cfg to set the numerix and
> backends when building the windows installers. Charlie, does that sound
> alright?

That's fine. I didn't use setup.cfg for the latest binaries though.

I think this is fixed. Please update from svn and try again.

Darren

···

On Wednesday 09 January 2008 10:15:54 am Francesco Pretto wrote:

2008/1/9, Darren Dale <darren.dale@...163...>:
> setup.py attempts to select the appropriate backend for you, based on
> what backends were available at build time. That selection is written
> into the default matplotlibrc file, which resides in
> site-packages/matplotlib/mpl-data. If matplotlib finds another
> matplotlibrc file (for example, in the current working directory, in
> $HOME/.matplotlib, etc), then it will use those settings instead. I would
> guess that is the source of the problem.

No, the problem is the default installed matplotlibrc, that is not
different from the one present in the source tree and has the default
selection:

backend : TkAgg

Now, i don't know if the build script is trying to modify it according
user selection or compile-time backend detection, but I'm wondering
why the same problem wasn't happening on linux, where I tipically
never install Tk runtime.

However, for me the problem is solved, but if there's a matplotlib
windows dev listening, here is my experience; first, i removed the
already installed "lib/site-packages/matplotlib/mpl-data/matplotlibrc"
. Afer, I went for clean compiling with a setup.cfg with these
configurations:

gtk = True
gtkagg = False
tkagg = False
wxagg = False
backend = GTK

Eventually, "python setup.py install" write again a
"site-packages/matplotlib/mpl-data/matplotlibrc" which still have:

backend : TkAgg

If this shouldn't happen, well, consider this a bug report :smiley:

2008/1/10, Darren Dale <darren.dale@...163...>:

I think this is fixed. Please update from svn and try again.

Darren

Fixed, thanks.

Francesco