17.04: using matplotlib with GTK-based backend?

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?

Answer

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.

Attribution
Source : Link , Question Author : jdpipe , Answer Author : jdpipe

Leave a Comment