Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime issue on M1 Mac: Symbol not found: _heif_check_filetype #41

Open
shanemcquillan opened this issue May 19, 2021 · 7 comments
Open

Comments

@shanemcquillan
Copy link

Hi Folks. I'm running into a runtime issue with pyheif on my M1 Mac:

>>> from pyheif_pillow_opener import register_heif_opener
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/shane/Downloads/Test/tempvenv/lib/python3.9/site-packages/pyheif_pillow_opener/__init__.py", line 2, in <module>
    import pyheif
  File "/Users/shane/Downloads/Test/tempvenv/lib/python3.9/site-packages/pyheif/__init__.py", line 3, in <module>
    import _libheif_cffi
ImportError: dlopen(/Users/shane/Downloads/Test/tempvenv/lib/python3.9/site-packages/_libheif_cffi.abi3.so, 2): Symbol not found: _heif_check_filetype
  Referenced from: /Users/shane/Downloads/Test/tempvenv/lib/python3.9/site-packages/_libheif_cffi.abi3.so
  Expected in: flat namespace
 in /Users/shane/Downloads/Test/tempvenv/lib/python3.9/site-packages/_libheif_cffi.abi3.so

I'm happy to provide any help here to get to the bottom of this; I've already tried a bunch of things on my end and haven't had any luck. Some notes that may help figure out what's going on:

  1. I'm using brew to install libheif. It's worth noting that brew install's packages in a different location on M1 Macs (/opt/homebrew) vs. Intel Macs (/usr/local)
  2. Folks were seeing a similar issue with the cryptography package on M1 Macs, which is related to cffi. I've tried installing that package specifying the brew header and shared library paths without any luck. I also tried the same for the pyheif install without any luck.
  3. I was able to successfully compare two .heic images using ImageMagick, so it appears that my installation of libheif is good.
  4. I've confirmed this symbol appears in the shared libraries I have installed:
$ grep -R "_heif_check_filetype" /opt/homebrew/lib 
Binary file /opt/homebrew/lib/libheif.dylib matches
Binary file /opt/homebrew/lib/libheif.1.dylib matches
Binary file /opt/homebrew/lib/libheif.a matches
  1. Installation also failed initially, but I was able to resolve that with the following command:
CPATH=/opt/homebrew/include LIBRARY_PATH=/opt/homebrew/lib pip install pyheif

Any ideas? Let me know what I can do to help get to the bottom of this.

@datatalking
Copy link

Hi @shanemcquillan I'm experiencing a similar issue on Mac Catalina 10.15.7 but I'm not on an M1.

I've posted my full stack trace on issue #43

I'm not sure they are the same issue, while I can install libheif it will not finish the install of pyheif

Requirement already satisfied: cffi>=1.0.0 in ./venv/lib/python3.8/site-packages (from pyheif) (1.14.5)
Requirement already satisfied: pycparser in ./venv/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) ... error
  ERROR: Command errored out with exit status 1:

@shanemcquillan
Copy link
Author

For anyone looking for a workaround on M1 Macs, I was able to get pyheif to install successfully with Rosetta2.

@panosangelopoulos
Copy link

@shanemcquillan Could you please provide us with more details (python version etc)?

@shanemcquillan
Copy link
Author

Hi @panosangelopoulos. Here's some versioning info:

Python 3.9.6
macOS Big Sur 11.2.3
libheif 1.12.0

Let me know if you need anything else.

@gavinsoe
Copy link

I believe I may have found a way to temporarily workaround this issue on m1 machines.

  1. similar to @shanemcquillan I had to setup a few things with Rosetta2. Not sure how he set that up, but for me I essentially have two different brew installations, brew for the m1 version and brow the x86. Guide to set that up can be found on the first half of this article

  2. Once that's done I used pyenv to manage different python environments. In this particular case I used python 3.9.10.
    If I were to install pyheif as is (via pip install pyheif) I would encounter the same issue above, namely _libheif_cffi.abi3.so, 0x0002): symbol not found in flat namespace '_heif_check_filetype'

  3. The solution was based on an issue found here (thanks to @ant32bit for pointing me there)
    what got it to work was running the following:

# brow is a synonym to a x86 brew installation, refer to #1 to see how it was setup.  otherwise use brew instead
python -m pip uninstall cffi pyheif pycparser

LDFLAGS="-L$(brow --prefix libheif)/lib" CFLAGS="-I$(brow --prefix libheif)/include" pip install pyheif --no-cache-dir

@EagleVee
Copy link

EagleVee commented Mar 4, 2022

Hi, I've written a full document, step by step on how to install pyheif on M1 Mac. You can found it here. Hope it helps!

@jhaenchen
Copy link

Been a year and a half, can we get this fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants