Python 是否可以在虚拟开发环境中使用matplotlib打开映像?

Python 是否可以在虚拟开发环境中使用matplotlib打开映像?,python,matplotlib,vagrant,Python,Matplotlib,Vagrant,我使用Ubuntu Vagrant box(虚拟环境,无GUI)进行开发,并决定尝试使用Python进行一些图像识别,但运行以下代码时无法打开图像: # I'm not sure if I can/should do this import in the same file, # but it doesn't give me any errors ... import matplotlib matplotlib.use('Agg') from PIL import Image import

我使用Ubuntu Vagrant box(虚拟环境,无GUI)进行开发,并决定尝试使用Python进行一些图像识别,但运行以下代码时无法打开图像:

# I'm not sure if I can/should do this import in the same file, 
# but it doesn't give me any errors ...
import matplotlib
matplotlib.use('Agg')

from PIL import Image
import numpy as np
import matplotlib.pyplot as plt

i = Image.open('images/dotndot.png')
image_array = np.asarray(i)
plt.imshow(image_array)
plt.show()
例如:什么也没发生。没有错误,也没有图像。
所以我想知道我的虚拟开发环境是否是罪魁祸首

没有GUI

这就是问题所在。这扇窗户在流浪汉的房间里悄无声息地打开,而你却看不见它

如果您坚持将Vagrant与GUI程序一起使用,则需要在主机上设置一个X服务器,并根据需要转发显示

如果您需要一个带有GUI的Linux环境,只需设置一个带有完整桌面的普通VM。

否则,如果您的代码主要是Python,请使用本地virtualenv

vagrant,就像在虚拟机中一样?您正在使用VirtualBox的GUI模式吗?否则,您需要启用X/SSH窗口转发Yes,就像在虚拟机中一样。不,我没有使用GUI模式。如何启用窗口转发?我建议您尝试打开Virtualbox本身,而不是使用Vagrant。此外,我不认为Wagrant Box默认提供桌面环境,所以我不确定您预期会发生什么