gpt4 book ai didi

python - 通过 ssh 使用 tkinter 没有显示名称和没有 $DISPLAY 环境变量

转载 作者:IT老高 更新时间:2023-10-28 22:04:38 25 4
gpt4 key购买 nike

我正在尝试运行一个在集群中输出 .png 文件的非常简单的代码。代码如下:

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 运行此代码,我会收到警告:

Unable to load library icui18n "Cannot load library icui18n:

.png 图像仍然生成,所以我在这里没有问题。但是,如果我在安装了 matplotlib 1.3.0 的集群中使用相同的命令和代码,则会失败并出现错误:

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

这里发生了什么?


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

#!/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 命令中。你需要做的就是这样写:

ssh -X "your_login"

关于python - 通过 ssh 使用 tkinter 没有显示名称和没有 $DISPLAY 环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19309085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com