Matplotlib backend missing modules with underscore


I've been using matplotlib for some time without problems. It's been a while since i needed the interactive plot functions (for which Tkaag was used). Since then i updated matplotlib a few times.

I tried to use it today, but it spawned an error.

/usr/local/lib/python2.7/dist-packages/matplotlib/backends/ in <module>()
----> 1 import _tkagg
      2 import Tkinter as Tk
      4 def blit(photoimage, aggimage, bbox=None, colormode=1):
      5     tk =

ImportError: No module named _tkagg

I tried a different backend, added the

backend      : GTKAgg

to matplotlibrc. Just to get the same error for a different module.

ImportError: No module named _backend_gdk

When I browsed for backends in /usr/local/lib/python2.7/dist-packages/matplotlib/backends/ i've noticed that all the required modules with underscore are missing.

alan@linux /usr/local/lib/python2.7/dist-packages/matplotlib/backends $ ls    backend_template.pyc
backend_agg.pyc       backend_macosx.pyc     backend_tkagg.pyc      backend_mixed.pyc
backend_cairo.pyc       backend_wxagg.pyc   backend_pdf.pyc
backend_cocoaagg.pyc        backend_wx.pyc        backend_ps.pyc
backend_emf.pyc    __init__.pyc    backend_qt4agg.pyc   Matplotlib.nib
backend_fltkagg.pyc        backend_qt4.pyc      qt4_compat.pyc
backend_gdk.pyc     qt4_editor     backend_qtagg.pyc
backend_gtkagg.pyc        tkagg.pyc   backend_qt.pyc
backend_gtkcairo.pyc       windowing.pyc        backend_svg.pyc

My current matplotlib version:

matplotlib      - 1.1.1        - active development (/usr/local/lib/python2.7/dist-packages)

I've tried uninstalled and reinstalling matplotlib with:

pip uninstall matplotlib
pip install matplotlib

and all went well.

Tips on setting on getting interactive plotting running again?


                matplotlib: 1.1.1

                    python: 2.7.3rc2 (default, Apr 22 2012, 22:35:38)  [GCC


                  platform: linux2


                     numpy: 1.6.2

                 freetype2: 14.1.8


                    libpng: 1.2.49

                   Tkinter: no

                            * Using default library and include directories for

                            * Tcl and Tk because a Tk window failed to open.

                            * You may need to define DISPLAY for Tk to work so

                            * that setup can determine where your libraries are

                            * located. Tkinter present, but header files are not

                            * found. You may need to install development

                            * packages.

                pkg-config: looking for pygtk-2.0 gtk+-2.0

                            * Package pygtk-2.0 was not found in the pkg-config

                            * search path. Perhaps you should add the directory

                            * containing `pygtk-2.0.pc' to the PKG_CONFIG_PATH

                            * environment variable No package 'pygtk-2.0' found

                            * Package gtk+-2.0 was not found in the pkg-config

                            * search path. Perhaps you should add the directory

                            * containing `gtk+-2.0.pc' to the PKG_CONFIG_PATH

                            * environment variable No package 'gtk+-2.0' found

                            * You may need to install 'dev' package(s) to

                            * provide header files.

                      Gtk+: no

                            * Could not find Gtk+ headers in any of

                            * '/usr/local/include', '/usr/include', '.'

           Mac OS X native: no

                        Qt: no

                       Qt4: Qt: 4.8.1, PyQt4: 4.9.1

                    PySide: no

                     Cairo: 1.8.8


                  datetime: present, version unknown

                  dateutil: matplotlib will provide

                      pytz: matplotlib will provide

    adding pytz


                    dvipng: 1.14

               ghostscript: 9.05

                     latex: 3.1415926

                   pdftops: 0.18.4
10/28/2012 7:46:22 PM

Accepted Answer

Thanks to peison's comment I've checked the installation log for matplotlib and it showed lots of dependencies.

I haven't noticed that before because the whole process of instalation ran really fast using

pip install matplotlib

and ended with a succesfull install.

To answer the question. The solution was to install packages tk and tk-dev, and rebuild matplotlib.

10/28/2012 8:26:02 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow