远程登陆服务器使用pycaffe时import caffe提示Gdk.Cursor.new(Gdk.CursorType.FLEUR)的错误。详细的报错如下:

(classify.py:21368): Gdk-CRITICAL **: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
Traceback (most recent call last):
  File "./classify.py", line 14, in <module>
    import caffe
  File "/home/heanfeng/caffe/python/caffe/__init__.py", line 1, in <module>
    from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
  File "/home/heanfeng/caffe/python/caffe/pycaffe.py", line 15, in <module>
    import caffe.io
  File "/home/heanfeng/caffe/python/caffe/io.py", line 2, in <module>
    import skimage.io
  File "/usr/local/lib/python2.7/dist-packages/skimage/io/__init__.py", line 15, in <module>
    reset_plugins()
  File "/usr/local/lib/python2.7/dist-packages/skimage/io/manage_plugins.py", line 93, in reset_plugins
    _load_preferred_plugins()
  File "/usr/local/lib/python2.7/dist-packages/skimage/io/manage_plugins.py", line 73, in _load_preferred_plugins
    _set_plugin(p_type, preferred_plugins['all'])
  File "/usr/local/lib/python2.7/dist-packages/skimage/io/manage_plugins.py", line 85, in _set_plugin
    use_plugin(plugin, kind=plugin_type)
  File "/usr/local/lib/python2.7/dist-packages/skimage/io/manage_plugins.py", line 255, in use_plugin
    _load(name)
  File "/usr/local/lib/python2.7/dist-packages/skimage/io/manage_plugins.py", line 299, in _load
    fromlist=[modname])
  File "/usr/local/lib/python2.7/dist-packages/skimage/io/_plugins/matplotlib_plugin.py", line 3, in <module>
    import matplotlib.pyplot as plt
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 114, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_gtk3agg.py", line 11, in <module>
    from . import backend_gtk3
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_gtk3.py", line 58, in <module>
    cursors.MOVE          : Gdk.Cursor.new(Gdk.CursorType.FLEUR),
TypeError: constructor returned NULL

跟师兄讨论后确定,这个错误的原因在于ssh连接服务器时候,import pyplot因为没有图形界面所导致的故障,解决的方法很简单,直接在ssh连接服务器的时候,添加-X的标记:

ssh 192.168.0.1 -X

就可以搞定了。当然还有另外一种解决的方法:在import pyplot之前,加入

matplotlib.use("Pdf")

同样也可以搞定!