You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Persistent ImportError: failed to find libmagic #238
I tried installing libmagic with both Homebrew and Macports (on a new Macbook Air M1 2020), but I'm unable to get it to work. What am I missing?
python-magic==0.4.22
import magic
Traceback (most recent call last):
File "<console>", line 1, in <module>
File ".../venv/lib/python2.7/site-packages/magic/__init__.py", line 210, in <module>
libmagic = loader.load_lib()
File ".../venv/lib/python2.7/site-packages/magic/loader.py", line 39, in load_lib
raise ImportError('failed to find libmagic. Check your installation')
ImportError: failed to find libmagic. Check your installation
% man libmagic
LIBMAGIC(3) BSD Library Functions Manual LIBMAGIC(3)
...
BSD June 8, 2019 BSD
To be honest, I just modified the python-magic to in my venv point to /opt/homebrew/Cellar/libmagic/*/lib/libmagic.dylib in addition to /usr/local/Cellar/libmagic/*/lib/libmagic.dylib for now...
Figured it out. The problem was that, due to compatibility issues with python2 on the M1 macbooks, I've had to install python2 via anaconda, which uses x86_64 architecture. Then I installed libmagic via Homebrew with arm64 architecture.
Then find your anaconda packages folder (search for the pkgs folder) and the libmagic folder within that and create a symlink in usr/local/lib to that libmagic.dylib. Mine looked like this:
cd /usr/local/lib
sudo ln -s /Users/******/opt/anaconda3/pkgs/libmagic-5.39-haaf19a9_0/lib/libmagic.dylib libmagic.dylib
Activity
cameron-emburse commentedon Mar 2, 2021
Seems like homebrew has changed to
/opt/homebrew/Cellarinstead of/usr/local/Cellar/where this package is looking.fsboehme commentedon Mar 2, 2021
Thanks for the quick reply! Combining your answer and this article I found earlier, I've created a symlink here:
(I first tried only creating a symlink from
/usr/local/Cellar/to/opt/homebrew/Cellarbut that didn't seem to do anything)Now I'm getting
any ideas?
fsboehme commentedon Mar 2, 2021
I'm guessing this is something. But no idea how to rectify...
cameron-emburse commentedon Mar 2, 2021
To be honest, I just modified the python-magic to in my venv point to
/opt/homebrew/Cellar/libmagic/*/lib/libmagic.dylibin addition to/usr/local/Cellar/libmagic/*/lib/libmagic.dylibfor now...fsboehme commentedon Mar 2, 2021
Figured it out. The problem was that, due to compatibility issues with python2 on the M1 macbooks, I've had to install python2 via anaconda, which uses x86_64 architecture. Then I installed libmagic via Homebrew with arm64 architecture.
So the solution was:
pkgsfolder) and the libmagic folder within that and create a symlink inusr/local/libto that libmagic.dylib. Mine looked like this:import magicworks!cameron-emburse commentedon Mar 3, 2021
FWIW, I think this is still an issue for 3.whatever apple m1 supports (3.9 in my case)
anentropic commentedon Sep 7, 2021
this error is still affecting anyone installing on arm mac due to:
python-magic/magic/loader.py
Line 17 in 5fa9055
and:
https://docs.brew.sh/FAQ#why-should-i-install-homebrew-in-the-default-location
I guess could be fixed just by adding extra default search paths
another option could be to detect the platform and parse the actual cellar path from output of
brew info --json libmagicanentropic commentedon Sep 7, 2021
ignore me...
'/opt/homebrew/lib'is searched in current version ofpython-magicand my homebrew has installed alibmagic.dylibsymlink there alreadythe problem is actually my project is using older version of python-magic 🤦