Failure to import dlib on M1 Mac
I can successfully install dlib with brew install dlib followed by pip install dlib, but it's failing on import with:
Python 3.9.2 (v3.9.2:1a79785e3e, Feb 19 2021, 09:06:10)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/shane/Library/Python/3.9/lib/python/site-packages/dlib/__init__.py", line 19, in <module>
from _dlib_pybind11 import *
ImportError: dlopen(/Users/shane/Library/Python/3.9/lib/python/site-packages/_dlib_pybind11.cpython-39-darwin.so, 2): Symbol not found: _DGifCloseFile
Referenced from: /Users/shane/Library/Python/3.9/lib/python/site-packages/_dlib_pybind11.cpython-39-darwin.so
Expected in: flat namespace
in /Users/shane/Library/Python/3.9/lib/python/site-packages/_dlib_pybind11.cpython-39-darwin.so
- Version: dlib==19.22.0
- Where did you get dlib: As mentioned above, both brew and PyPI
- Platform: macOS 11.2.3, Darwin Kernel Version 20.3.0: Thu Jan 21 00:06:51 PST 2021; root:xnu-7195.81.3~1/RELEASE_ARM64_T8101 arm64
I'm happy to provide any help and do whatever testing's needed to get to the bottom of this.
Warning: this issue has been inactive for 35 days and will be automatically closed on 2021-08-03 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.
I'm still hitting this, even using Rosetta2. Let me know if there's anything I can do to help debug.
Try this. It worked for me with python 3.9.6 and without Rosetta.
python3 -m venv env
brew install cmake
brew install dlib
source env/bin/activate
python3 -m pip install dlib
Then you should be able to run python3 and import dlib
That works! Thank you @jtweaver! I was on python 3.9.2, maybe it had a bug that was causing the failures I was seeing. The upgrade to 3.9.6 did the trick.
it is working Thank you a lot @jtweaver I am using Python 3.8.8
That's nice but what if you need an older python version? In my case, I'm constrained to python 3.6 - what can I do then?
solved it by linking 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)
none of the above worked for me ... Python 3.9.6 , libpng 1.6.38, dlib-19.24.0. Still got the error when trying to import dlib in python
File "/Users/francesco/Library/Python/3.9/lib/python/site-packages/dlib/init.py", line 19, in
none of the above worked for me ... Python 3.9.6 , libpng 1.6.38, dlib-19.24.0. Still got the error when trying to import dlib in python
File "/Users/francesco/Library/Python/3.9/lib/python/site-packages/dlib/init.py", line 19, in from _dlib_pybind11 import * ImportError: dlopen(/Users/francesco/Library/Python/3.9/lib/python/site-packages/_dlib_pybind11.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace (_png_do_expand_palette_rgb8_neon)
I'v got the same problem.
Same issue. Can't figure out.
Mac M2 chip
python3.11
dlib-19.24.1
_dlib_pybind11.cpython-311-darwin.so, 0x0002): symbol not found in flat namespace '_DGifCloseFile'
Same issue. Can't figure out. Mac M2 chip python3.11 dlib-19.24.1
_dlib_pybind11.cpython-311-darwin.so, 0x0002): symbol not found in flat namespace '_DGifCloseFile'
ImportError: dlopen(/opt/homebrew/lib/python3.11/site-packages/dlib-19.24.99-py3.11-macosx-13-arm64.egg/_dlib_pybind11.cpython-311-darwin.so, 0x0002): symbol not found in flat namespace '_XAllocSizeHints
Got a similar error on an M1 Pro. Any help here? Python 3.11.5 dlib 19.24.2
Okay, I had the symbol not found in flat namespace '_DGifCloseFile' error. I used the technique from this past issue: https://github.com/davisking/dlib/issues/1694 of doing a brew uninstall --ignore-dependencies giflib and was able to get past it
I'm now at:
lib/python3.11/site-packages/_dlib_pybind11.cpython-311-darwin.so, 0x0002): symbol not found in flat namespace '_XAllocColor'
which suggests that my X11 is installed or linked incorrectly? I suspect that @cmok is having a similar problem, but their error is coming from a different library.
I'm on arm64 m2 chip and osx 12.0.1
Same for my M3 Mac.
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/dlib-19.24.99-py3.12-macosx-10.9-universal2.egg/_dlib_pybind11.cpython-312-darwin.so, 0x0002): symbol not found in flat namespace '_DGifCloseFile'
BTW, it works on Intel Mac. I am working on an assignment, thus I don't have lots of time solving this issue.