Python Forum
image does not show with pillow
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
image does not show with pillow
#1
hi everone
? why the image does not show with pillow in python
buran write Apr-13-2025, 05:47 PM:
Please, use descriptive title
Larz60+ write Apr-13-2025, 09:31 AM:
Rather than attaching code, please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Attached Files

Thumbnail(s)
   
Reply
#2
although i have install the pillow moduel with
pip install pillow
Reply
#3
I couldn't get it to work either. Here's the code:
from PIL import Image
my_image = Image.open("image1.PNG")
my_image.show()
Here's the error:
Output:
Traceback (most recent call last): File "tester.py", line 9, in <module> my_image.show() File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2146, in show _show(self, title=title, command=command) File "/usr/lib/python3/dist-packages/PIL/Image.py", line 3085, in _show _showxv(image, **options) File "/usr/lib/python3/dist-packages/PIL/Image.py", line 3091, in _showxv ImageShow.show(image, title, **options) File "/usr/lib/python3/dist-packages/PIL/ImageShow.py", line 47, in show if viewer.show(image, title=title, **options): File "/usr/lib/python3/dist-packages/PIL/ImageShow.py", line 67, in show return self.show_image(image, **options) File "/usr/lib/python3/dist-packages/PIL/ImageShow.py", line 87, in show_image return self.show_file(self.save_image(image), **options) File "/usr/lib/python3/dist-packages/PIL/ImageShow.py", line 168, in show_file subprocess.Popen(args) File "/usr/lib/python3.8/subprocess.py", line 858, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib/python3.8/subprocess.py", line 1639, in _execute_child self.pid = _posixsubprocess.fork_exec( TypeError: expected str, bytes or os.PathLike object, not NoneType
I'm on Linux Mint 20.3 using Python 3.8.10

Attached Files

Thumbnail(s)
   
Reply
#4
Works fine for me using Idle as Python IDE and Ubuntu as OS

from PIL import Image

image = '/home/pedro/Pictures/icebergs_in_barbate.png'
# Opens an image in RGB mode 
im = Image.open(image)      
# Size of the image in pixels (size of original image) 
# Just for information
width, height = im.size
im.show()
Maybe you are not giving the correct path to your image??
Reply
#5
Thank you @Pedroski55. I don't think that is the problem. New code:
from PIL import Image
image = './image1.PNG'
# Open an image in RGB mode 
im = Image.open(image)      
# print image attributes
print (im.format, im.size, im.mode)
# shows image was loaded
# now error trying to display image
im.show()
The image seems to be loading correctly but not displaying.
Output:
PNG (480, 360) RGB Traceback (most recent call last): File "tester.py", line 14, in <module> im.show() File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2146, in show _show(self, title=title, command=command) File "/usr/lib/python3/dist-packages/PIL/Image.py", line 3085, in _show _showxv(image, **options) File "/usr/lib/python3/dist-packages/PIL/Image.py", line 3091, in _showxv ImageShow.show(image, title, **options) File "/usr/lib/python3/dist-packages/PIL/ImageShow.py", line 47, in show if viewer.show(image, title=title, **options): File "/usr/lib/python3/dist-packages/PIL/ImageShow.py", line 67, in show return self.show_image(image, **options) File "/usr/lib/python3/dist-packages/PIL/ImageShow.py", line 87, in show_image return self.show_file(self.save_image(image), **options) File "/usr/lib/python3/dist-packages/PIL/ImageShow.py", line 168, in show_file subprocess.Popen(args) File "/usr/lib/python3.8/subprocess.py", line 858, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib/python3.8/subprocess.py", line 1639, in _execute_child self.pid = _posixsubprocess.fork_exec( TypeError: expected str, bytes or os.PathLike object, not NoneType
It knows that the image is 480/360 RGB but will not display it.
Reply
#6
(Apr-13-2025, 07:32 PM)BashBedlam Wrote: It knows that the image is 480/360 RGB but will not display it.
Error you see when calling im.show() indicates that the external image viewer that pillow trying to use isn’t set up properly.
In other words, one of the arguments being passed to the system’s subprocess call is coming out as None.

Your system might not have a default image viewer installed (or it isn’t available in your PATH).
For instance, Linux systems often rely on utilities like display (from ImageMagick) or xdg-open.

Can instal a viewer eg sudo apt-get install imagemagick
You can force Pillow to use a specific viewer by setting the environment variable before running your script:
import os
from PIL import Image

os.environ["PIL_IMAGE_SHOW"] = "/usr/bin/display"  # Adjust this path as needed
image = './image1.PNG'
im = Image.open(image)
print(im.format, im.size, im.mode)
im.show()
Gribouillis likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter Pillow Resize Image Looks Choppy While Resizing AaronCatolico1 2 2,525 Jan-03-2023, 05:41 PM
Last Post: AaronCatolico1
  PIL Image im.show() no show! Pedroski55 2 2,469 Sep-12-2022, 10:19 PM
Last Post: Pedroski55
  PIL Image im.show() no show! Pedroski55 6 12,413 Feb-08-2022, 06:32 AM
Last Post: Pedroski55
  Invert Pillow image colours chesschaser 5 7,116 Jul-11-2020, 02:59 PM
Last Post: chesschaser
  cv2 show image mcgrim 4 14,537 Nov-04-2019, 11:41 PM
Last Post: MckJohan
  show grayscale image using matplotlib zyb1003 1 17,367 Nov-01-2017, 11:45 AM
Last Post: heiner55
  Closing an image opened by Pillow in Window Photo Viewer bigmit37 16 30,742 Aug-11-2017, 03:54 AM
Last Post: grahamnt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020