TclError:EC2上没有显示名和$display环境变量

2024-06-13 12:09:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在Amazon EC2(Linux AMI)上使用iPython。我已经安装了Anaconda并启动了iPython来测试我已经创建的一些脚本。现在我只对在终端上运行它感兴趣(作为笔记本)。

在我的代码开始时,我总是这样做:

import json
import numpy as np
import pandas as pd
from pandas import Series, DataFrame

但是,我尝试从文本编辑器中使用CTRL+C,然后在终端中使用%paste,得到错误:

TclError: no display name and no $DISPLAY environment variable

如果我按照这个建议尝试ssh-X name@host No display name and no $DISPLAY environment variable using tkinter through ssh,我会得到:

/opt/X11/bin/xauth:  file /Users/adrianp/.Xauthority does not exist
Warning: untrusted X11 forwarding setup failed: xauth key data not generated
X11 forwarding request failed on channel 0

为了解决这个问题,我尝试了https://superuser.com/questions/249045/x11-forwarding-from-amazon-ec2-ami,但仍然收到一个警告:

 Warning: untrusted X11 forwarding setup failed: xauth key data not generated

同样的错误:

TclError: no display name and no $DISPLAY environment variable

根据这个建议Generating a PNG with matplotlib when DISPLAY is undefined(这似乎无关紧要,但我已经尝试了一切)我做到了:

import matplotlib
matplotlib.use('Agg')

在导入其他内容之前仍然会出现相同的错误。

对如何解决这个问题有什么想法吗?我真的很想使用粘贴魔法函数来输入函数等


Tags: andnonameimportenvironmentmatplotlib错误display
1条回答
网友
1楼 · 发布于 2024-06-13 12:09:41

这更多的是linux/X11问题,而不是python问题。另外,这个过程可能会有点过火——你最好在本地运行ipython或者启动一个web笔记本。

无论如何,你应该:

  • 安装tigervnc
  • 运行vncserver(由于这是一个面向internet的服务器,请使用安全密码或阻止防火墙中的端口)
  • 安装tk(我认为您已经完成了此操作)
  • 编辑sshd_config(很可能是/etc/ssh/sshd_config)并启用 x11前进(x11前进是)。
  • 登录到服务器,将-Y选项传递给ssh(ssh-Y user@server)

然后您应该能够启动ipython并使用%paste。

相关问题 更多 >