-1

I am dealing with an issue on the Image.open() function from PIL in Python.

I try to open an image from a path / folder saved on a string:

path_and_filename = "c:\tmp\test.jpeg"

image = Image.open(path_and_filename)

Then I get the error:

fp = builtins.open(filename, "rb")

PermissionError: [Errno 13] Permission denied: 'c:\\tmp\\test.jpeg'

If I define the path and filename as a raw string, it works:

path_and_filename = r"c:\tmp\test.jpeg"

image = Image.open(path_and_filename)

The error message regarding "permission" makes no sense, since it works on the same file if it is definied as a raw string.

Do you see any solution or recommendetation for this issue?

Thanks a lot!

2 Answers2

0

The "permission" issue was solved:

The files were copied into a hotfolder monitored by watchdog and the watchdog started the Image.open() function.

The files were sometimes not completelly copied into the folder and the function was already trying to open it. That is why I got the "permission" error message.

After setting a delay time.sleep() before calling the open function, it was possible to call it.

Note: the script was working on the raw variable since I set an already copied file name on it.

-1

Put it in the same file path that all your .py files are and than you don’t need the path you just call the file name

   Image = image.open(‘test.jpg’)
Pmac1687
  • 9
  • 1