为什么 pyheif 在 python 导入时崩溃?

Mor*_*kus 4 python

当尝试在 python 3 程序中导入“pyheif”时,我得到下面的崩溃转储。

谁能解释一下如何成功导入这个包?我尝试了多个版本,确保安装了“wheel”等,搜索了 Stack 并进行了其他搜索,但尚未找到如何解决。

提前致谢!

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.
Run Code Online (Sandbox Code Playgroud)

小智 5

我们需要更多地了解您的环境,例如您拥有什么类型的机器,您是否使用 docker,如果是,您使用什么类型的 docker 镜像,等等。

我会尽力给您一个通用的答案,也许您回来后我们可以详细讨论您的问题。

brew install libffi libheif
Run Code Online (Sandbox Code Playgroud)

如果您使用的是 docker,请将以下包添加到RUN命令中

RUN apt-get install -y libffi-dev libheif-dev libde265-dev
Run Code Online (Sandbox Code Playgroud)