Mendo101 Mendo101 - 4 months ago 54
Python Question

Trouble accessing exif information with PIL.Image._getexif()

I am attempting to pull exif information from '.nef' files for the purposes of automatically sorting files into folders based on the retrieved data.

Based on my reading, it appears that PIL is a good choice for getting the information into Python.

I have PIL installed and it imports correctly, as does the PIL.Image module.

The problem arises when I attempt to call 'PIL.Image._getexif()'

from PIL import Image
from PIL.ExifTags import TAGS

firstfile = 'link to file'
exif = Image._getexif(firstfile)

That gets this error:

AttributeError: 'module' object has no attribute '_getexif'

A longer version of the code also gets an error:

def get_exif(fn):
ret = {}
i =
info = i._getexif()
for tag, value in info.items():
decoded = TAGS.get(tag, tag)
ret[decoded] = value
return ret

exifinfo = get_exif(firstfile)

This fails with:

AttributeError: _getexif

Perhaps I have PIL installed wrong? Why is '_getexif()' not able to be called?

The only google results for a direct search of "AttributeError: 'module' object has no attribute '_getexif'" are old/404'd not helpful, leading me to believe this is not a common problem to have.


It would appear that PIL is not an appropriate module for what I was trying to accomplish.

I was able to achieve my ends (sorting items in a folder based on EXIF info) by using PyExifTool to extract EXIF info from nef files.