没有显示名称,没有$ DISPLAY环境变量,使用tkinter通过ssh [英] No display name and no $DISPLAY environment variable using tkinter through ssh

查看:336
本文介绍了没有显示名称,没有$ DISPLAY环境变量,使用tkinter通过ssh的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个非常简单的代码,该代码在群集中输出一个.png文件.这是代码:

I'm trying to run a very simple code that outputs a .png file in a cluster. Here's the code:

import matplotlib.pyplot as plt
import numpy as np

x = np.random.randn(60)
y = np.random.randn(60)

plt.scatter(x, y, s=20)

out_png = 'path/to/store/out_file.png'
plt.savefig(out_png, dpi=150)

如果我在安装了matplotlib 1.2.1的系统中使用命令python simple_code.py运行此代码,则会收到警告:

If I run this code with the command python simple_code.py in my system which has matplotlib 1.2.1 installed I get the warning:

Unable to load library icui18n "Cannot load library icui18n:

.png图像仍然产生,所以我在这里没有问题.但是,如果我在安装了matplotlib 1.3.0的集群中使用相同的命令和代码,它将失败并显示以下错误:

The .png image is still produced so I have no problems here. But if I use the same command and code in a cluster which has matplotlib 1.3.0 installed it fails with the error:

Traceback (most recent call last):
  File "simple_code.py", line 33, in <module>
    plt.scatter(x, y, s=20)
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 3078, in scatter
    ax = gca()
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 803, in gca
    ax =  gcf().gca(**kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 450, in gcf
    return figure()
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 423, in figure
    **kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 79, in new_figure_manager
    return new_figure_manager_given_figure(num, figure)
  File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 87, in new_figure_manager_given_figure
    window = Tk.Tk()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1712, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

这是怎么回事?

添加,这是我用来登录集群的脚本:

Add, this is the script I use to login into the cluster:

#!/usr/bin/expect

set login "user"
set addr "address1"
set addr2 "address2"
set pw "password"

spawn ssh -X $login@$addr
expect "$login@$addr\'s password:"
send "$pw\r"
expect "$login@host:"
send "ssh -X $addr2\r"
expect "$login@$addr\'s password:"
send "$pw\r"
interact

推荐答案

您的问题出在ssh命令中.您需要做的是这样写:

Your problem is in ssh command. What you need to do is to write it this way:

ssh -X "your_login"

这篇关于没有显示名称,没有$ DISPLAY环境变量,使用tkinter通过ssh的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆