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

Does python-magic work on Apple Silicon? #262

Closed
soimkim opened this issue Feb 24, 2022 · 6 comments · May be fixed by #294
Closed

Does python-magic work on Apple Silicon? #262

soimkim opened this issue Feb 24, 2022 · 6 comments · May be fixed by #294

Comments

@soimkim
Copy link

soimkim commented Feb 24, 2022

When Python-magic is installed and executed on Apple Silicon(m1), the following bug occurs. Is there any workaround?

 ImportError: dlopen(/usr/local/Cellar/libmagic/5.41/lib/libmagic.dylib, 0x0006): tried: '/usr/local/Cellar/libmagic/5.41/lib/libmagic.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/libmagic.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/lib/libmagic.dylib' (no such file), '/usr/local/Cellar/libmagic/5.41/lib/libmagic.1.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/libmagic.1.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/lib/libmagic.1.dylib' (no such file)

failed to find libmagic.  Check your installation
@ahupp
Copy link
Owner

ahupp commented Feb 24, 2022

It looks like you're running a native (ARM) python, but python-magic is finding an Intel copy of the libmagic shared library.

Do you know how /usr/local/Cellar/libmagic/5.41/lib/libmagic.dylib got installed? It looks like homebrew now supports M1 officially (just as of a few weeks ago), so could you try get M1-native homebrew packages installed?

Alternatively, you could run python from your current Intel homebrew install instead of (presumably) the OS install, and it would use the runtime translation and presumably work at the cost of a speed hit.

@soimkim
Copy link
Author

soimkim commented Feb 26, 2022

/usr/local/Cellar/libmagic/5.41/lib/libmagic.dylib was installed with brew install libmagic.
Even after re-installing with brew reinstall, the result is the same. 😢

I'll check again if m1-native homebrew is installed.
Thanks for the reply. 🙂

@wshs0713
Copy link

wshs0713 commented Mar 3, 2022

Here has a strange solution:

pip3 install python-magic-bin
pip3 uninstall python-magic

But I don't know why it works...

@ahupp
Copy link
Owner

ahupp commented Mar 8, 2022

@wshs0713 not sure why that would work...

@soimkim are you using homebrew 3.0? That's the one with M1 support, and it defaults to /opt/homebrew according to this page: https://mac.install.guide/homebrew/index.html

@soimkim
Copy link
Author

soimkim commented Mar 8, 2022

When I installed libmagic I installed it wrong.
Reinstalled brew and re-installed libmagic and it works fine. 😄
(python-magic-bin did not work in m1, so I installed it as python-magic.)

Thanks for answering my question.👍

@HansBambel
Copy link

After running

brew install libmagic
pip install python-magic

I had the issue that my python platform was for x86_64, but brew installed the arm64 binaries of libmagic. This resulted in a hidden error about a platform mismatch (#279).

Check python-platform:

import platform
platform.machine()

I then uninstalled the recently installed arm64-libmagic-binaries and installed another homebrew with x86_64 architecture (this is likely overkill):

# How to install it with x86 libomp:
# install x86_64 variant of brew 
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
# install x86_64 variant of libmagic
arch -x86_64 /usr/local/bin/brew install libmagic

The alternative would have been to set up the conda environment as arm64 (probably easier): https://stackoverflow.com/questions/65415996/how-to-specify-the-architecture-or-platform-for-a-new-conda-environment-apple

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

Successfully merging a pull request may close this issue.

4 participants