ImportError: No module named _backend_gdk


I am starting to get some insight into interactive plotting with python and matplotlib using pyGTK+. Therefore I took a look at the example given at the matplotlib website.

This is a short exerpt of the Code:

#!/usr/bin/env python
Example of embedding matplotlib in an application and interacting with
a treeview to store data.  Double click on an entry to update plot

import pygtk
import gtk
from gtk import gdk

import matplotlib
matplotlib.use('GTKAgg')  # or 'GTK'
from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas

from numpy.random import random
from matplotlib.figure import Figure

Ones I try to run this Script in the Terminal I get the following error:

Traceback (most recent call last):
  File "", line 15, in <module>
    from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/", line 33, in <module>
    from matplotlib.backends.backend_gdk import RendererGDK, FigureCanvasGDK
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/", line 29, in <module>
    from matplotlib.backends._backend_gdk import pixbuf_get_pixels_array
ImportError: No module named _backend_gdk

I have python 2.7 and pygtk 2.24 installed.

Can anyone figure out where the error is located? I think it might be connected to some linking issues?

2/14/2017 8:53:29 AM

Note that the Debian/Ubuntu package you need is not 'pygtk2-devel' but 'python-gtk2-dev':

sudo apt-get install python-gtk2-dev

should fix this error on these platforms.

12/17/2013 12:34:08 AM

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