TypeError constructor returned NULL while importing pyplot in ssh

烈酒焚心 提交于 2020-04-12 09:27:52

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/31328436/typeerror-constructor-returned-null-while-importing-pyplot-in-ssh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!