'The open file operation failed issue in Python image compressing code using MAC OS M1 Chip

I am building a python script to compress the image on my M1 Macbook Air. But an error is coming

The open file operation failed.

Below is the python code:

import PIL
from PIL import Image
from tkinter.filedialog import *

file_path = askopenfilename()
img = PIL.Image.open(file_path)
myHeight, myWidth = img.size

img = img.resize((myHeight, myWidth), PIL.Image.ANTIALIAS)
save_path = asksaveasfilename()

img.save(save_path+"_compressed.JPG")

Error screenshot

Screenshot of the error which came in the terminal

I have also imported the PILLOW.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source