2

On a new 17.04 Ubuntu system, with python and python-matplotlib, I wanted to plot using the Matplotlib GTKAgg or GTKCairo backends. This works nicely in 16.04, but is broken in 17.04, as a result of the following:

>>> import matplotlib.backends._backend_gdk
ImportError: No module named _backend_gdk

But the same command works perfectly in 16.04. Consequently

import matplotlib; matplotlib.use("GTKCairo"); 
import pylab; pylab.plot([1,2],[3,4]);pylab.show()

works perfectly in 16.04, and fails with the 'no module named' error (as above) on 17.04. I can see that my 17.04 system has the file /usr/lib/python2.7/dist-packages/matplotlib/backends/_backend_gdk.x86_64-linux-gnu.so, so how is this error arising? Any suggestions for workarounds?

You'reAGitForNotUsingGit
  • 14,669
  • 9
  • 48
  • 83
jdpipe
  • 749
  • 8
  • 21
  • 1
    I also installed `python-matplotlib` using `sudo apt install python-matplotlib` and tried what you did but I was able to make a plot and therefore could not reproduce your error. How did you install matplotlib? Presumably using `apt`/`apt-get`? – edwinksl Aug 22 '17 at 12:17
  • Yes, specifically as recorded here: http://ascend4.org/Building_ASCEND#Ubuntu_17.04 (and under 16.04 below). Did you try the direct import matplotlib.backends._backend_gdk from inside an ipython console on 17.04? And just to check... did you also run matplotlib.use("GTKCairo") on 17.04? Was it a clean system, or had you had other matplotlib/gtk libs installed previously? – jdpipe Aug 31 '17 at 23:42
  • 1
    A note: on Ubuntu 18.04, they seem to have permanently(?) removed support for `GTKAgg` and `GTKCairo` from Matplotlib, meaning that you can't use GTK2 for plotting anymore. You have to use GTK3 instead. – jdpipe Aug 09 '18 at 02:29

1 Answers1

1

Problem solved... while restoring files from my earlier system, I had inadvertently copied an installation of matplotlib in ~/.local/lib/python2.7, and it was this version, rather than the Ubuntu version that was running and giving the error.

jdpipe
  • 749
  • 8
  • 21