Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does pyheif crash on python import?

Tags:

python

When trying to import 'pyheif' in a python 3 program, I get this crash dump below.

Can anyone explain how to successfully import this package? I have tried multiple versions, made sure "wheel" was installed, etc., searched Stack and done other searches but have not found out how to resolve.

Thanks in advance!

Collecting pyheif
  Using cached pyheif-0.5.1.tar.gz (17 kB)
Requirement already satisfied: cffi>=1.0.0 in /Users/user/venv/HEICToJPG/lib/python3.8/site-packages (from pyheif) (1.14.4)
Requirement already satisfied: pycparser in /Users/user/venv/HEICToJPG/lib/python3.8/site-packages (from cffi>=1.0.0->pyheif) (2.20)
Building wheels for collected packages: pyheif
  Building wheel for pyheif (setup.py): started
  Building wheel for pyheif (setup.py): finished with status 'error'
  Running setup.py clean for pyheif
Failed to build pyheif
Installing collected packages: pyheif
    Running setup.py install for pyheif: started
    Running setup.py install for pyheif: finished with status 'error'

  ERROR: Command errored out with exit status 1:
   command: /Users/user/venv/HEICToJPG/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/ts/yxklk_lj3f32_q1kkljflz5h0000gn/T/pip-install-q3c_oaef/pyheif_88ea55c096834e3e8b4bbae48bc5e633/setup.py'"'"'; __file__='"'"'/private/var/folders/ts/yxklk_lj3f32_q1kkljflz5h0000gn/T/pip-install-q3c_oaef/pyheif_88ea55c096834e3e8b4bbae48bc5e633/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/ts/yxklk_lj3f32_q1kkljflz5h0000gn/T/pip-wheel-8kzdauau
       cwd: /private/var/folders/ts/yxklk_lj3f32_q1kkljflz5h0000gn/T/pip-install-q3c_oaef/pyheif_88ea55c096834e3e8b4bbae48bc5e633/
  Complete output (27 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.9-x86_64-3.8
  creating build/lib.macosx-10.9-x86_64-3.8/pyheif
  copying pyheif/error.py -> build/lib.macosx-10.9-x86_64-3.8/pyheif
  copying pyheif/constants.py -> build/lib.macosx-10.9-x86_64-3.8/pyheif
  copying pyheif/__init__.py -> build/lib.macosx-10.9-x86_64-3.8/pyheif
  copying pyheif/reader.py -> build/lib.macosx-10.9-x86_64-3.8/pyheif
  copying pyheif/writer.py -> build/lib.macosx-10.9-x86_64-3.8/pyheif
  creating build/lib.macosx-10.9-x86_64-3.8/pyheif/data
  copying pyheif/data/version.txt -> build/lib.macosx-10.9-x86_64-3.8/pyheif/data
  warning: build_py: byte-compiling is disabled, skipping.

  running build_ext
  generating cffi module 'build/temp.macosx-10.9-x86_64-3.8/_libheif_cffi.c'
  creating build/temp.macosx-10.9-x86_64-3.8
  building '_libheif_cffi' extension
  creating build/temp.macosx-10.9-x86_64-3.8/build
  creating build/temp.macosx-10.9-x86_64-3.8/build/temp.macosx-10.9-x86_64-3.8
  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -I/usr/local/include -I/usr/include -I/Users/user/venv/HEICToJPG/include -I/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 -c build/temp.macosx-10.9-x86_64-3.8/_libheif_cffi.c -o build/temp.macosx-10.9-x86_64-3.8/build/temp.macosx-10.9-x86_64-3.8/_libheif_cffi.o
  build/temp.macosx-10.9-x86_64-3.8/_libheif_cffi.c:570:15: fatal error: 'libheif/heif.h' file not found
       #include "libheif/heif.h"
                ^~~~~~~~~~~~~~~~
  1 error generated.
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for pyheif
    ERROR: Command errored out with exit status 1:
     command: /Users/user/venv/HEICToJPG/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/ts/yxklk_lj3f32_q1kkljflz5h0000gn/T/pip-install-q3c_oaef/pyheif_88ea55c096834e3e8b4bbae48bc5e633/setup.py'"'"'; __file__='"'"'/private/var/folders/ts/yxklk_lj3f32_q1kkljflz5h0000gn/T/pip-install-q3c_oaef/pyheif_88ea55c096834e3e8b4bbae48bc5e633/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/ts/yxklk_lj3f32_q1kkljflz5h0000gn/T/pip-record-phe46c7r/install-record.txt --single-version-externally-managed --compile --install-headers /Users/user/venv/HEICToJPG/include/site/python3.8/pyheif
         cwd: /private/var/folders/ts/yxklk_lj3f32_q1kkljflz5h0000gn/T/pip-install-q3c_oaef/pyheif_88ea55c096834e3e8b4bbae48bc5e633/
    Complete output (27 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.9-x86_64-3.8
    creating build/lib.macosx-10.9-x86_64-3.8/pyheif
    copying pyheif/error.py -> build/lib.macosx-10.9-x86_64-3.8/pyheif
    copying pyheif/constants.py -> build/lib.macosx-10.9-x86_64-3.8/pyheif
    copying pyheif/__init__.py -> build/lib.macosx-10.9-x86_64-3.8/pyheif
    copying pyheif/reader.py -> build/lib.macosx-10.9-x86_64-3.8/pyheif
    copying pyheif/writer.py -> build/lib.macosx-10.9-x86_64-3.8/pyheif
    creating build/lib.macosx-10.9-x86_64-3.8/pyheif/data
    copying pyheif/data/version.txt -> build/lib.macosx-10.9-x86_64-3.8/pyheif/data
    warning: build_py: byte-compiling is disabled, skipping.

    running build_ext
    generating cffi module 'build/temp.macosx-10.9-x86_64-3.8/_libheif_cffi.c'
    creating build/temp.macosx-10.9-x86_64-3.8
    building '_libheif_cffi' extension
    creating build/temp.macosx-10.9-x86_64-3.8/build
    creating build/temp.macosx-10.9-x86_64-3.8/build/temp.macosx-10.9-x86_64-3.8
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -I/usr/local/include -I/usr/include -I/Users/user/venv/HEICToJPG/include -I/Library/Frameworks/Python.framework/Versions/3.8/include/python3.8 -c build/temp.macosx-10.9-x86_64-3.8/_libheif_cffi.c -o build/temp.macosx-10.9-x86_64-3.8/build/temp.macosx-10.9-x86_64-3.8/_libheif_cffi.o
    build/temp.macosx-10.9-x86_64-3.8/_libheif_cffi.c:570:15: fatal error: 'libheif/heif.h' file not found
         #include "libheif/heif.h"
                  ^~~~~~~~~~~~~~~~
    1 error generated.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/user/venv/HEICToJPG/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/ts/yxklk_lj3f32_q1kkljflz5h0000gn/T/pip-install-q3c_oaef/pyheif_88ea55c096834e3e8b4bbae48bc5e633/setup.py'"'"'; __file__='"'"'/private/var/folders/ts/yxklk_lj3f32_q1kkljflz5h0000gn/T/pip-install-q3c_oaef/pyheif_88ea55c096834e3e8b4bbae48bc5e633/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/ts/yxklk_lj3f32_q1kkljflz5h0000gn/T/pip-record-phe46c7r/install-record.txt --single-version-externally-managed --compile --install-headers /Users/user/venv/HEICToJPG/include/site/python3.8/pyheif Check the logs for full command output.
like image 732
Morkus Avatar asked Sep 12 '25 00:09

Morkus


1 Answers

We need to know a bit more about your environment, like what type of machine do you have, are you using docker, if yes what type of docker image are you using, etc.

I will try to give you a generic answer and maybe we can discuss in detail your problem once you will be back.

  • Try to follow the commands as described in repo https://github.com/carsales/pyheif
brew install libffi libheif

In case that you are using docker then add the following packages into a RUN command

RUN apt-get install -y libffi-dev libheif-dev libde265-dev
like image 131
Panos Angelopoulos Avatar answered Sep 13 '25 15:09

Panos Angelopoulos