[英]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.
在我测试它时,我当然在脚本的文件夹中有 jpg。
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这些都没有奏效,output 是
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()
Try using the absolute path to the image尝试使用图像的绝对路径
from PIL import Image
try:
image = Image.open("/path/to/pic.jpg")
except:
print("Please rename the file to 'pic.jpg' and restart the script")
quit()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.