[Python] How to extract metadata from .heic image files on Windows 11 with Python?

Discussão em 'Python' iniciado por Stack, Agosto 8, 2025.

  1. Stack

    Stack Membro Participativo

    I'm running Python 3.10 on Windows 11. I need to extract metadata from .heic image files. Here is what I tried:

    1. ExifRead


    I tried with ExifRead (see https://pypi.org/project/ExifRead/) but that failed:

    >>> import exifread
    >>> f = open("path/to/img.heic", 'rb')
    >>> tags = exifread.process_file(f)
    Traceback (most recent call last):
    File "C:\Python310\lib\site-packages\exifread\heic.py", line 171, in get_parser
    return defs[box.name]
    KeyError: 'hdlr'

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "C:\Python310\lib\site-packages\exifread\__init__.py", line 137, in process_file
    offset, endian, fake_exif = _determine_type(fh)
    File "C:\Python310\lib\site-packages\exifread\__init__.py", line 109, in _determine_type
    offset, endian = heic.find_exif()
    File "C:\Python310\lib\site-packages\exifread\heic.py", line 268, in find_exif
    meta = self.expect_parse('meta')
    File "C:\Python310\lib\site-packages\exifread\heic.py", line 159, in expect_parse
    return self.parse_box(box)
    File "C:\Python310\lib\site-packages\exifread\heic.py", line 177, in parse_box
    probe(box)
    File "C:\Python310\lib\site-packages\exifread\heic.py", line 195, in _parse_meta
    psub = self.get_parser(box)
    File "C:\Python310\lib\site-packages\exifread\heic.py", line 173, in get_parser
    raise NoParser(box.name) from err
    exifread.heic.NoParser: hdlr

    2. pyheif


    I tried to install the pyheif module, but there is no build for Windows.

    3. pillow


    I tried with the pillow module (aka PIL):

    >>> from PIL import Image
    >>> img = Image.open("path/to/img.HEIC")
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "C:\Python310\lib\site-packages\PIL\Image.py", line 3280, in open
    raise UnidentifiedImageError(msg)
    PIL.UnidentifiedImageError: cannot identify image file 'C:/Backup/Pictures_2023/IMG_0620.HEIC'

    Continue reading...

Compartilhe esta Página