2021年3月11日星期四

Pillow won't open an image in the same directory. "FileNotFoundError: [Errno 2] No such file or directory:"

The pillow library won't open an image in the same directory as the script anymore, while it used to. I haven't changed anything to do with how the file is loaded. I of course have the jpg in the folder with the script while I'm testing it.

I've tried the import to all three of these since I've read that works:

from PIL import Image  
import PIL.Image  
import PIL  

None of these have worked and the output is

FileNotFoundError: [Errno 2] No such file or directory: 'pic.jpg'  

The code loading the image is:

def main(new_width=300):            try:          image = PIL.Image.open("pic.jpg")      except:          print("Please rename the file to 'pic.jpg' and restart the script")          quit()  
https://stackoverflow.com/questions/66593205/pillow-wont-open-an-image-in-the-same-directory-filenotfounderror-errno-2 March 12, 2021 at 10:07AM

没有评论:

发表评论