Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError constructor returned NULL while importing pyplot in ssh

I am having difficulties importing matplotlib.pyplot when I am using ssh to access my local lab cluster.

Indeed, trying to import matplotlib.pyplot as plt is giving me an error. I have tried to just import matplotlib as mpl and this is fine, so something specifically about importing pyplot is wrong here. The last line of the trace-back says

File '/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtk3.py', line 58, in <module> cursors.MOVE : Gdk.Cursor.new(Gdk.CursorType.FLEUR), TypeError: constructor returned NULL

Can anyone identify the error here? Or, is there a way I can circumvent the error and still use the pyplot tools?

If it makes a difference, I am using Windows 8.

like image 621
MCT Avatar asked Jul 09 '15 21:07

MCT


1 Answers

You are failing to load GTK. Most likely, it is because you do not have access to an X11 server and can't draw windows (which is what GTK does).

Try matplotlib.use("Pdf") before importing pyplot. Then you won't need to load GTK and it won't fail. You can still make plots and save them to pdf but you can't draw them on screen.

Alternatively, you could try forwarding X11. Then you could see the windows as if you were on the host machine. With a Linux client, this is done by logging on via ssh -X hostname. With a Windows client, it can be done but not as smoothly.

like image 176
mmdanziger Avatar answered Oct 20 '22 10:10

mmdanziger