6

Here is a bit of my code:

from PIL import Image

image = Image.open('fall-foliage-1740841_640.jpg')
image.show()

The error is when the default photo viewer is started and shows the error

"It looks like the image was moved or renamed"

Restarting doesn't help. I am just starting using PIL and can't find a way round this.

I appreciate any help. Thanks!!!

Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
Patrick Mutuku
  • 1,095
  • 15
  • 13
  • What OS are you using? – Mark Ransom Nov 09 '16 at 02:39
  • windows 10. I have seen a similar problem on windows website but the only solution given is restarting the computer which doesn't work – Patrick Mutuku Nov 09 '16 at 02:41
  • See http://stackoverflow.com/questions/8932976/python-imaging-library-show-on-windows. I think I have a better answer somewhere else, still looking for it. – Mark Ransom Nov 09 '16 at 02:44
  • Nope, I think that was the best answer I could come up with. That's rather unfortunate. – Mark Ransom Nov 09 '16 at 02:51
  • Thanks I found it. Quick solution – Patrick Mutuku Nov 09 '16 at 02:55
  • Solution: Edit C:\Python26\lib\site-packages\PIL\ImageShow.py, and around line 99, replace with the following line: return "start /wait %s && PING 127.0.0.1 -n 5 > NUL && del /f %s" % (file, file) T – Patrick Mutuku Nov 09 '16 at 02:56
  • 1
    The basic explanation is that the command line window that pops up when the code is being executed destroys the temp file of the image before it is processed and rendered by the photo viewer. The solution is delaying the destroying long enough for it to be rendered which is achieved by :: Edit C:\Python26\lib\site-packages\PIL\ImageShow.py, and around line 99, replace with the following line: return "start /wait %s && PING 127.0.0.1 -n 5 > NUL && del /f %s" % (file, file) – Patrick Mutuku Nov 09 '16 at 03:01

1 Answers1

0

You can just add a prompt to keep the python script from closing.

from PIL import Image

image = Image.open('fall-foliage-1740841_640.jpg')

image.show()

input()

Essentially, The problem is that when the image is opened, it's stored in temporary memory. So when the program closes, the image is not saved and is lost from memory. There for when the Photos app or whatever app you are using to view the image, searches for the image, it's already gone when the script is finished executing.

Hope this helps