2

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 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.