【发布时间】:2022-03-16 20:27:56
【问题描述】:
我正在尝试从“.nef”文件中提取 exif 信息,以便根据检索到的数据将文件自动分类到文件夹中。
根据我的阅读,PIL 似乎是将信息导入 Python 的不错选择。
我已经安装了 PIL,它可以正确导入,PIL.Image 模块也是如此。
当我尝试调用 'PIL.Image._getexif()' 时出现问题
from PIL import Image
from PIL.ExifTags import TAGS
firstfile = 'link to file'
exif = Image._getexif(firstfile)
得到这个错误:
AttributeError: 'module' object has no attribute '_getexif'
较长版本的代码也会出错:
def get_exif(fn):
ret = {}
i = Image.open(fn)
info = i._getexif()
for tag, value in info.items():
decoded = TAGS.get(tag, tag)
ret[decoded] = value
Image.close(fn)
return ret
exifinfo = get_exif(firstfile)
这失败了:
AttributeError: _getexif
也许我的 PIL 安装错了?为什么 '_getexif()' 不能被调用?
注意事项: 直接搜索“AttributeError:'module'对象没有属性'_getexif'”的唯一谷歌结果是旧的/404'd没有帮助,让我相信这不是一个常见的问题。
【问题讨论】:
标签: python image python-imaging-library exif