bork
bork

Reputation: 1674

Is it possible to open an image with matplotlib in within a virtual development environment?

I use an Ubuntu Vagrant box (virtual environment, no GUI) for my development purposes and I decided to try out some image recognition with Python, but I can't get the image to open when I run the following code:

# 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()

I.e.: nothing happens. No errors and no image.
So I was wondering if my virtual dev environment is the culprit here?

Upvotes: 2

Views: 1347

Answers (1)

OneCricketeer
OneCricketeer

Reputation: 191864

no GUI

Well, that's the issue. The window is silently opening within Vagrant, and you can't see it.

If you insist on using Vagrant with GUI programs, you need to setup an X Server on your host machine, and forward the display, as mentioned here

If you need a Linux environment with a GUI, just setup a normal VM with a full desktop.
Otherwise, and if your coding is primarily Python, use a local virtualenv

Upvotes: 2

Related Questions