Gtk-警告**:无法打开显示: [英] Gtk-WARNING **: cannot open display:

查看:172
本文介绍了Gtk-警告**:无法打开显示:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用通过Windows中的无业游民者运行ubuntu 14.04的数据科学工具箱. 我安装了OpenCV,并尝试了一个非常简单的python代码.

I am using Data science toolbox running ubuntu 14.04 through vagrant in windows. I installed OpenCV and tried a very simple python code.

import cv2
import numpy as np 
import matplotlib.pyplot as plt 

img = cv2.imread('image1.jpg' , cv2.IMREAD_GRAYSCALE) 
cv2.imshow('image' , img)
cv2.waitKey(0)
cv2.destroyAllwindows()

运行此代码时出现错误-

When i run this code i get an error -

(image:1267): Gtk-WARNING **: cannot open display:

我已经在互联网上进行搜索,但找不到适合我的解决方案.

I have searched on internet but not able to find a solution working for me.

我已经尝试过-

export DISPLAY=:0.0
export DISPLAY=:0

等等. 我也尝试过xhost + localhost,但这会给出另一个错误

and many more. I have also tried xhost +localhost but this gives another error

xhost:  unable to open display ""

任何人都知道解决此问题的方法.

Anyone know a way to solve this problem.

推荐答案

您可以将显示转发到主机,在Vagrantfile中,添加以下行

You can forward the display to your host, in your Vagrantfile, add the following lines

  config.ssh.forward_agent = true
  config.ssh.forward_x11 = true

您将需要在Windows计算机上运行的X服务器(我个人在Mac上使用 Quartz ,您需要获取Windows的等效版本,例如 Xming ),然后在vagrant up引导时您的VM,当您运行X程序时,它将在您的主机上弹出.

You will need a X-server running on your windows machine (I personally use Quartz on my mac, you would need to get an equivalent for windows, like Xming) and then when you vagrant up to boot your VM, when you will run an X-program it will pop-up on your host.

这篇关于Gtk-警告**:无法打开显示:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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