Cris Cruz
Cris Cruz

Reputation: 11

Python dlib not working properly on Apple Silicon chip (M4)

I want to use dlib on Python. I installed it without any issue. The problem is that, when I try to import it, I get this error:

Traceback (most recent call last):
  File "/Users/elgamernovato/Projects/Free Code/Python/Test Proyecto Rene/test.py", line 1, in <module>
    import dlib
  File "/Users/elgamernovato/Projects/Free Code/Python/Test Proyecto Rene/venv/lib/python3.13/site-packages/dlib/__init__.py", line 19, in <module>
    from _dlib_pybind11 import *
ImportError: 
dlopen(/Users/elgamernovato/Projects/Free Code/Python/Test Proyecto Rene/venv/lib/python3.13/site-packages/_dlib_pybind11.cpython-313-darwin.so, 0x0002): 
tried: 
'/Users/elgamernovato/Projects/Free Code/Python/Test Proyecto Rene/venv/lib/python3.13/site-packages/_dlib_pybind11.cpython-313-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), 
'/System/Volumes/Preboot/Cryptexes/OS/Users/elgamernovato/Projects/Free Code/Python/Test Proyecto Rene/venv/lib/python3.13/site-packages/_dlib_pybind11.cpython-313-darwin.so' (no such file), 
'/Users/elgamernovato/Projects/Free Code/Python/Test Proyecto Rene/venv/lib/python3.13/site-packages/_dlib_pybind11.cpython-313-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64'))

I installed cmake, boost and openblas using brew. I installed dlib again for arm:

CMAKE_PREFIX_PATH=$(brew --prefix) arch -arm64 pip install dlib --no-binary dlib

But still the same error.

I even ensured python is working for arm64 with

arch -arm64 python3 -c "import platform; print(platform.machine())"

On the terminal I ran uname -m to confirm that I am using arm64.

I expected dlib to import smoothly, but simply importing it causes errors.

Upvotes: 1

Views: 42

Answers (2)

Cris Cruz
Cris Cruz

Reputation: 11

Yeah guys, I found the solution in this video: https://www.youtube.com/watch?v=F0V5AbxwzSE

First, I ran pip3 install cmake, then pip3 install dlib==29.24.2, now everything it's working fine.

Upvotes: 0

Starship
Starship

Reputation: 752

Try installing it first through Homebrew. Run this to install it through Homebrew (make sure you have Homebrew downloaded) and it will install dlib (and dependencies):

python3 -m venv env
brew install cmake
brew install boost
brew install boost-python
brew install dlib
source env/bin/activate
python3 -m pip install numpy
python3 -m pip install scipy
python3 -m pip install scikit-image
python3 -m pip install dlib

Upvotes: 0

Related Questions