2

I am using Spyder with python 2.7 and matplotlib on a windows machine.

I am trying to run my script and I am getting the following error:

runfile('C:/Python27/Scripts/python-serial-plot.py', wdir=r'C:/Python27/Scripts')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 601, in runfile
    execfile(filename, namespace)
  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 66, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)
  File "C:/Python27/Scripts/python-serial-plot.py", line 8, in <module>
    from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_gtkagg.py", line 14, in <module>
    from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_gtk.py", line 36, in <module>
    from matplotlib.backends.backend_gdk import RendererGDK, FigureCanvasGDK
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_gdk.py", line 33, in <module>
    from matplotlib.backends._backend_gdk import pixbuf_get_pixels_array
ImportError: No module named _backend_gdk

I went to the directory where the backends are stored and can't see _backend_gdk.

How can I fix this issue?

Stephen Rauch
  • 44,696
  • 30
  • 102
  • 125
sci-guy
  • 2,154
  • 4
  • 22
  • 44

2 Answers2

0

You need to change your graphics backend to fix this error. In Spyder you need to go to

Tools > Preferences > IPython console > Graphics > Graphics backend

and select there either Inline or Automatic there.

Carlos Cordoba
  • 31,214
  • 10
  • 86
  • 118
-1

You can switch the backend to list all backends:

In [5]: import matplotlib

In [6]: matplotlib.rcsetup.all_backends

Then use matplotlib.use('some_backend') to choose another, I don't use windows so cannot recommend what to use but you can try different ones and see what works best.

The matplotlib.use('some_backend') should be before any import matplotlib.pyplot etc.. statements

what is a backend

Padraic Cunningham
  • 168,988
  • 22
  • 228
  • 312
  • This doesn't seem to address the issue the asker is facing. They know of backends and have imported one, but `matplotlib` is throwing an error anyways. – Seanny123 Feb 14 '17 at 06:11