问题
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