0

I have setted the default application --gimp to open image in my os (debian 11 + lxde).

enter image description here

The below python code will open the image in your default image viewer in so:
open a new window to show image

>>> from PIL import Image                                                                                
>>> img = Image.open('test.png')
>>> img.show() 

Why no new window opened and gimp start to show the image when executing in my os?

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
showkey
  • 482
  • 42
  • 140
  • 295
  • First, make sure you have the image path is correct by replacing its name with its absolute path. Second, try opening images with `matplotlib`. `import matplotlib.pyplot as plt` `img = Image.open(path_to_the_image)` `plt.imshow(image)` `plt.show()` – TaQuangTu Sep 14 '21 at 02:14
  • 1
    PIL is looking for `eog` or `xv` to view the image with, so try installing either of those packages. – Mark Setchell Sep 14 '21 at 08:56

1 Answers1

0

To install matplotlib in Debian run sudo apt install python3-matplotlib. Use pyplot from the matplotlib Python module to display the image as follows.

import matplotlib.pyplot as plt
from PIL import Image
plt.imshow(Image.open('test.png'))
plt.show()

Alternatively install eog with sudo apt install eog and your original code will display the image in a new window. Please note that if the image is small then the new window will also be small, and you might not notice that it is open.

karel
  • 5,489
  • 46
  • 45
  • 50