Gtk-WARNING **:无法打开显示::0.0 --- Ubuntu 14.04

Gtk-WARNING **: cannot open display: :0.0 --- Ubuntu 14.04

我刚刚在亚马逊 EC2 实例 (ubuntu 14.04) 上安装了 OpenCV 3.2.0。当我尝试 运行 任何示例程序时,我收到错误 Gtk-WARNING **: cannot open display: :0.0 在线回答类似问题对我不起作用。我试过了 export DISPLAY=:0.0 export DISPLAY=:0 我尝试了 xhost +localhost 并收到了 xhost: unable to open display ":0.0"

这个 post 描述了与我完全相同的问题,但我没有使用 Vagrant,所以没有 "Vagrantfile" 而且我不知道 EC2 中的等价物是什么实例。

有人知道为什么会这样吗?

我在 Ubuntu 16.04 上使用 ssh 连接到 Ubuntu 16.04.2 服务器。我可以做到以下几点:

xhost +
ssh -Y -i .ssh/my.pem ubuntu@ecxxxxxxx.eu-west-1.compute.amazonaws.com
sudo apt install x11-apps
xclock

这会在我的本地显示器上启动 xclock 小程序。请注意 ssh 之前的 xhost + 和 ssh 命令上的 -Y 标志。我正在使用 xclock 来测试我从 x11-apps 安装的。您应该能够以类似的方式启动 OpenCV。