0

I want to load an image ('venice-boat.jpg') that is located in 'images\' in my program. I use PIL for that. However, python gives me an error stating "OSError: [Errno 22] Invalid argument: 'images\x0benice-boat.jpg'"

As you can see, one of the character has been changed. I have no idea why.

If I move image file to a root directory, I can open with same commands, only removing 'images\' from my path. But It's not a solution for future.

import os
from PIL import Image

# gives incorrect pathing
boat = Image.open('images\venice-boat.jpg')

# properly loads image
boat = Image.open('venice-boat.jpg')

It's either a corruption in python or in Windows. How should I deal with this? How should I search for what is broken?

1 Answers1

0

As you are using Windows try changing:

boat = Image.open('images\venice-boat.jpg')

To:

boat = Image.open('images\\venice-boat.jpg')
Dipen Dadhaniya
  • 4,550
  • 2
  • 16
  • 24