0

I am trying to open an image using python; I wrote the following code :

from PIL import Image
im=Image.open("IMG_1930.jpg")
im.show()

But the windows photo viewer opens but it shows the following message instead of the photos:

"windows photo viewer can not open this picture because either the picture is deleted , or it isn't in a location that is accessible."

2
  • 1
    Try providing a full path to the image. Commented Jul 3, 2014 at 4:10
  • Either do what @jsbueno said or covert the image to a gif Commented May 27, 2016 at 14:19

2 Answers 2

3

The show method in PIL is a poor's man way of viewing an image - it has got a hardcoded image viewer application, and writes your image data to a temporary file before calling that as an external application.

What is happening there is that you are either having problems with Windows' uneven access rights policies, and the viewer can't open the file in Python's temporary directory, or there is a problem with Window's problematic path specifications - it might even be a bug in PIL, that renders the temporary paht generated by PIL unusable by the image viewer.

If you are using show in a windowing application, use your tookit's way of viewing images to display it instead - otherwise, if it is a simpler application, build up a Tkitner Window and put the image in it, instead of show.

import sys

import Tkinter
from PIL import Image, ImageTk

window = Tkinter.Tk()
img = Image.open("bla.png")
img.load()
photoimg = ImageTk.PhotoImage(img)
container = Tkinter.Label(window, image=photoimg)
container.pack()

Tkinter.mainloop()

(Linux users: some distributions require the separate install of Tkinter support for PIL/PILLOW. In Fedora, for example, one has to install the python-pillow-tk package )

Sign up to request clarification or add additional context in comments.

Comments

0

I also had problems with this. Take a look at this post it fixed my problem: PIL image show() doesn't work on windows 7

Good luck fixing it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.