LeoHsiao1 / pyexiv2

Read and write image metadata, including EXIF, IPTC, XMP, ICC Profile.
GNU General Public License v3.0
196 stars 39 forks source link

FileNotFoundError: [Errno 2] No such file or directory: '1.JPG' #104

Closed dandancow874 closed 1 year ago

dandancow874 commented 1 year ago

初学者不太懂,请教一下这是什么错误 这个图片单独打开不会出错,批量处理的时候会出错,但是有的图片又不出错.

import pyexiv2 import os from fractions import Fraction from PIL import Image, ImageDraw, ImageFont, ImageOps

picpath= 'C:/Users/danda/Desktop/now/照片'

for root, dirs, files in os.walk(picpath): for file in files: print(os.path.join(root, file))

    with open(file, 'rb') as f:
        with pyexiv2.ImageData(f.read()) as img:
            data = img.read_exif()
            print(data)

错误:

raceback (most recent call last): File "c:\Users\danda\Desktop\now\test5.py", line 12, in with open(file, 'rb') as f: ^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: '1.JPG'

LeoHsiao1 commented 1 year ago

可能是 open(file, 'rb') 中,输入的 file 文件路径不对。比如 '1.JPG' 是在当前目录下寻找该文件,'D:\test\1.JPG' 是在指定目录下寻找该文件。

dandancow874 commented 1 year ago

第一个问题解决了.. 又出现了了这个错误

RuntimeError: Directory Sony1 with 26112 entries considered invalid; not read. Directory Thumbnail with 44032 entries considered invalid; not read.

LeoHsiao1 commented 1 year ago

报错表示,图片中的元数据不符合标准格式,因此不能读取。 如果 read_exif()、read_iptc()、read_xmp() 都不能读取到元数据,则只能考虑用其它软件来处理你的图片。

dandancow874 commented 1 year ago

感谢大佬回复