Soke Soke - 1 year ago 118
Python Question

TypeError constructor returned NULL while importing pyplot in ssh

I am having difficulties importing

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
is wrong here. The last line of the trace-back says

File '/usr/lib64/python2.7/site-packages/matplotlib/backends/',
line 58, in <module>
cursors.MOVE :,
TypeError: constructor returned NULL

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

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

Answer Source

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.