简体   繁体   English

Pillow 不会在同一目录中打开图像。 “FileNotFoundError:[Errno 2] 没有这样的文件或目录:”

[英]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.

相关问题 FileNotFoundError:[错误2]没有此类文件或目录。 的Ubuntu - FileNotFoundError: [Errno 2] No such file or directory. Ubuntu 打开 FileNotFoundError: [Errno 2] 没有这样的文件或目录: - with open FileNotFoundError: [Errno 2] No such file or directory: FileNotFoundError: [Errno 2] 没有这样的文件或目录。 Python 无法正确读取文件 - FileNotFoundError: [Errno 2] No such file or directory. Python not reading files correctly open() 给出 FileNotFoundError/IOError: Errno 2 No such file or directory - open() gives FileNotFoundError/IOError: Errno 2 No such file or directory 无法打开资源文件,pygame 错误:“FileNotFoundError:没有这样的文件或目录。” - Could not open resource file, pygame error: "FileNotFoundError: No such file or directory." FileNotFoundError [Errno 2] 没有这样的文件或目录: - FileNotFoundError [Errno 2] No such file or directory: FileNotFoundError: [Errno 2] 没有这样的文件或目录? - FileNotFoundError: [Errno 2] No such file or directory? FileNotFoundError:[Errno 2]没有这样的文件或目录: - FileNotFoundError: [Errno 2] No such file or directory: Pygame 错误:FileNotFoundError:没有这样的文件或目录。 他们已经在同一个文件夹中 - Pygame Error : FileNotFoundError: No such file or directory. They are already in the same folder FileNotFoundError:[错误2]没有这样的文件或目录,但是文件在那里 - FileNotFoundError: [Errno 2] No such file or directory, But the file is there
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM