我正在尝试从“.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没有帮助,让我相信这不是一个常见的问题。
最佳答案
对于我想要完成的任务来说,PIL 似乎不是一个合适的模块。
我能够通过使用 PyExifTool 实现我的目的(根据 EXIF 信息对文件夹中的项目进行排序)从 nef 文件中提取 EXIF 信息。
关于python - 使用 PIL.Image._getexif() 访问 exif 信息时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40215380/