Gtk-WARNING **: cannot open display:

十年热恋 提交于 2019-12-24 16:26:36

问题


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.

I have tried -

export DISPLAY=:0.0
export DISPLAY=:0

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.


回答1:


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

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.



来源:https://stackoverflow.com/questions/34919821/gtk-warning-cannot-open-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!