【问题标题】:TclError: no display name and no $DISPLAY environment variable on EC2TclError:EC2 上没有显示名称和 $DISPLAY 环境变量
【发布时间】:2015-05-08 11:13:25
【问题描述】:

我想在 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

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

/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')

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

关于如何解决这个问题的任何想法?我真的很想使用粘贴魔术功能来输入功能/等。

【问题讨论】:

  • 尝试使用魔术粘贴功能时的另一个变化是TclError: couldn't connect to display "localhost:10.0"
  • 关于 localhost 错误...试过了,但仍然无法使用魔法粘贴 stackoverflow.com/questions/2443702/…
  • 这似乎是一个 IPython 3.0 错误,FWIW 我在 ARM 服务器上遇到了同样的问题

标签: python amazon-ec2 ipython anaconda


【解决方案1】:

这更像是一个 linux/X11 问题,而不是一个 python 问题。此外,这个过程可能会有点过头了——你最好只在本地运行 ipython 或启动一个网络笔记本。

无论如何,你应该:

  • 安装tigervnc
  • 运行 vncserver(因为这是面向 Internet 的服务器,请使用安全密码或在防火墙中阻止端口)
  • 安装 tk(我想你已经这样做了)
  • 编辑 sshd_config(很可能是 /etc/ssh/sshd_config)并启用 X11Forwarding(X11Forwarding 是)。
  • 将 -Y 选项传递给 ssh (ssh -Y user@server) 登录到您的服务器

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

【讨论】:

  • 太棒了,感谢您的详细回复。我忙于其他项目,所以我需要一些时间来测试一下。
猜你喜欢
  • 2016-10-02
  • 2018-09-03
  • 2019-11-03
  • 1970-01-01
  • 1970-01-01
  • 2019-10-09
  • 2020-10-24
  • 1970-01-01
  • 2014-01-10
相关资源
最近更新 更多