dlib icon indicating copy to clipboard operation
dlib copied to clipboard

Compatibility with Apple Silicon M1

Open VlasovKirill opened this issue 5 years ago • 18 comments

I get the error every time after import dlib:

    import dlib
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/dlib/__init__.py", line 19, in <module>
    from _dlib_pybind11 import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_dlib_pybind11.cpython-39-darwin.so, 2): no suitable image found.  Did find:
	/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_dlib_pybind11.cpython-39-darwin.so: mach-o, but wrong architecture
	/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_dlib_pybind11.cpython-39-darwin.so: mach-o, but wrong architecture

I try rebuild dlib with some settings arch.

I am using Apple Silicon M1:

  • face_recognition version: latest
  • Python version: 3.9.1 [Clang 6.0 (clang-600.0.57)] on darwin / 3.8.2 [Clang 12.0.0 (clang-1200.0.32.27)] on darwin
  • Operating System: macOS Big Sur 11.1

file "$( "$(which python3)" -c "import sys;print(sys.executable)" )"

/Library/Developer/CommandLineTools/usr/bin/python3: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64:Mach-O 64-bit executable arm64]
/Library/Developer/CommandLineTools/usr/bin/python3 (for architecture x86_64):	Mach-O 64-bit executable x86_64
/Library/Developer/CommandLineTools/usr/bin/python3 (for architecture arm64):	Mach-O 64-bit executable arm64

VlasovKirill avatar Dec 19 '20 11:12 VlasovKirill

Warning: this issue has been inactive for 35 days and will be automatically closed on 2021-02-02 if there is no further activity.

If you are waiting for a response but haven't received one it's possible your question is somehow inappropriate. E.g. it is off topic, you didn't follow the issue submission instructions, or your question is easily answerable by reading the FAQ, dlib's official compilation instructions, dlib's API documentation, or a Google search.

dlib-issue-bot avatar Jan 24 '21 09:01 dlib-issue-bot

Warning: this issue has been inactive for 43 days and will be automatically closed on 2021-02-02 if there is no further activity.

If you are waiting for a response but haven't received one it's possible your question is somehow inappropriate. E.g. it is off topic, you didn't follow the issue submission instructions, or your question is easily answerable by reading the FAQ, dlib's official compilation instructions, dlib's API documentation, or a Google search.

dlib-issue-bot avatar Feb 01 '21 09:02 dlib-issue-bot

Having the same issue with Apple Silicon

grischka avatar Feb 01 '21 09:02 grischka

Tried on python 3.8.2 and 3.9.1 with the same result. Any idea how to proceed?

dwojcik92 avatar Feb 04 '21 09:02 dwojcik92

For me this config worked I have used the default python3 shipped with my Mac m1 and used terminal with rosetta Then I have created a new python3 environment using python3 -m venv env_name We need homebrew to install the dependencies We need cmake and dlib which can be installed as follows brew install cmake brew install dlib After successful installation of cmake and dlib, activate your environment using source env_name/bin/activate Then install dlib in python3 python3 -m pip install dlib after successful installation launch python3 and import dlib This worked for me

adityadhinavahi avatar Mar 17 '21 04:03 adityadhinavahi

Warning: this issue has been inactive for 35 days and will be automatically closed on 2021-05-01 if there is no further activity.

If you are waiting for a response but haven't received one it's possible your question is somehow inappropriate. E.g. it is off topic, you didn't follow the issue submission instructions, or your question is easily answerable by reading the FAQ, dlib's official compilation instructions, dlib's API documentation, or a Google search.

dlib-issue-bot avatar Apr 21 '21 08:04 dlib-issue-bot

Warning: this issue has been inactive for 42 days and will be automatically closed on 2021-05-01 if there is no further activity.

If you are waiting for a response but haven't received one it's possible your question is somehow inappropriate. E.g. it is off topic, you didn't follow the issue submission instructions, or your question is easily answerable by reading the FAQ, dlib's official compilation instructions, dlib's API documentation, or a Google search.

dlib-issue-bot avatar Apr 28 '21 08:04 dlib-issue-bot

Notice: this issue has been closed because it has been inactive for 45 days. You may reopen this issue if it has been closed in error.

dlib-issue-bot avatar May 01 '21 08:05 dlib-issue-bot

still have same problem

dayojohn19 avatar Aug 23 '21 10:08 dayojohn19

On m1 Mac install miniforge3 as mentioned here https://developer.apple.com/metal/tensorflow-plugin/

brew install cmake
brew install dlib
python -m venv .venv
source .venv/bin/activate
pip install dlib
face_recognition

Worked for me!

sid7631 avatar Sep 15 '21 23:09 sid7631

This issue is already a year old, but doesn't seem to be solved. The above solution only works for Python versions 3.9 and higher, but what if you must use a lower python version?

Does anyone still have this issue, like me? Any solutions in sight?

agilebean avatar Dec 29 '21 07:12 agilebean

@agilebean I met this problem today and solved it finally. You may check your cmake: file which cmake, make sure it is arm64 executable.

leo-scorpio avatar Feb 08 '22 09:02 leo-scorpio

solved it by linking the libpng library for me:

brew install libpng
export C_INCLUDE_PATH=/opt/homebrew/Cellar/libpng/1.6.37/include
export LIBRARY_PATH=/opt/homebrew/Cellar/libpng/1.6.37/lib
pip3 install dlib --force-reinstall 

(replace 1.6.37 by your installed version of libpng)

buseynehannes avatar Sep 01 '22 07:09 buseynehannes

I am still facing that problem with all the above suggested solutions.

import dlib
 File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/dlib/__init__.py", line 19, in <module>
   from _dlib_pybind11 import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/_dlib_pybind11.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace (_png_do_expand_palette_rgb8_neon

Do you have any other recommendations?

niktheo avatar Sep 01 '22 10:09 niktheo

Has there been any updates on this issue, I have tried all suggested solutions and still receive the same error.

dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/_dlib_pybind11.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace (_png_do_expand_palette_rgb8_neon)

AndrewW1999 avatar Oct 18 '22 11:10 AndrewW1999

I am having the same issue except with a different missing name space.

Currently using an M1 mac and a conda virtual environment. I have already installed cmake, used the brew install libpng and pip install --upgrade setuptools

I have only been able to install dlib using pip install dlib==19.17.0 as just pip install dlib was giving me the cmake wheel error

ImportError: dlopen(//opt/anaconda3/envs/DeepFake/lib/python3.10/site-packages/dlib.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '_XAllocColor'

romitbarua avatar Oct 27 '22 02:10 romitbarua

On m1 Mac install miniforge3 as mentioned here https://developer.apple.com/metal/tensorflow-plugin/

brew install cmake
brew install dlib
python -m venv .venv
source .venv/bin/activate
pip install dlib
face_recognition

Worked for me!

I had the same problem on M2 - MacOS Sonoma 14.3. After I brew install cmake and dlib to my system, I have no problem in any other virtual environment.

Firstly, on my terminal:

brew install cmake
brew install dlib

Then, start a clean environemt

python -m venv .venv
source .venv/bin/activate           # I did not see any reason for pip install dlib
pip install opencv-python
pip install face_recognition
pip install git+https://github.com/ageitgey/face_recognition_models.      # asked when I tried to test import face_recognition 

Test imports

python
import cv2
import face_recognition

Python 3.12.4

Package                 Version
----------------------- ---------
click                   8.1.7
dlib                    19.24.5
face-recognition        1.3.0
face_recognition_models 0.3.0
numpy                   2.0.1
opencv-python           4.10.0.84
pillow                  10.4.0
pip                     24.0

maritaganta avatar Aug 06 '24 14:08 maritaganta

@maritaganta Having the same issue with M2, Any idea how to proceed?

damscassiani1994 avatar Jan 10 '25 14:01 damscassiani1994