Search code examples
pythonimageimportpython-imaging-librarytypeerror

Img.show() showing error In Python pillow


This is the code

from PIL import Image
im = Image.open('hi.png')
im.show()

Error msg is here

Traceback (most recent call last):
  File "/home/kd/Documents/python/modules/pillow_image.py", line 3, 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
[Finished in 178ms with exit code 1]

It should open the image in imageviewer in linux but I am geting this error


Solution

  • What Pillow version do you have? I encounter this problem some time ago, on older version when .show() method would result in this error if no title was given. Try using:

    ...
    im.show(title="some title")