一尘不染

RuntimeError:无效的DISPLAY变量

linux

我通过使用中的ssh命令在另一台机器上运行python脚本linux。我也运行了以下命令:

source ~/.bashrc

登录另一台计算机后,为了在新计算机中定义正确的路径。即使我尝试通过定义后端来遵循此问题中的说明,也收到了运行以下python代码行的错误消息。

>>> import matplotlib
>>> import pylab as plt
>>> matplotlib.use('Agg')
>>> import numpy as np
>>> x=np.arange(0,2,0.001)
>>> y=np.sin(x)**2+4*np.cos(x)
>>> fig = plt.figure()
>>> plt.plot(x,y,'r.')

错误讯息

This probably means that Tcl wasn't installed properly.
Traceback (most recent call last):
  File "Systematic_Optimised.py", line 513, in <module>
    fig = plt.figure()
  File "/vol/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py", line 435, in figure
    **kwargs)
  File "/vol/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py", line 47, in new_figure_manager
    return new_figure_manager_given_figure(num, thisFig)
  File "/vol/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py", line 54, in new_figure_manager_given_figure
    canvas = FigureCanvasQTAgg(figure)
  File "/vol/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py", line 72, in __init__
    FigureCanvasQT.__init__(self, figure)
  File "/vol/aibn84/data2/zahra/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_qt4.py", line 68, in __init__
    _create_qApp()
  File "/vol/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py", line 138, in _create_qApp
    raise RuntimeError('Invalid DISPLAY variable')
RuntimeError: Invalid DISPLAY variable

任何建议如何解决问题


阅读 398

收藏
2020-06-07

共1个答案

一尘不染

您必须声明matplotlib.use('agg')之前import pylab as plt

2020-06-07