For me, this is a mac M1 specific issue, solved by linking libpng:
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)
I ended up having to install dlib from source:
git clone https://github.com/davisking/dlib.git
cd dlib
python setup.py install --set DLIB_PNG_SUPPORT=1 --compiler-flags "-I/usr/local/include -L/opt/homebrew/lib -lpng"
This was based on this issue on dlib which recommends installing libpng and this issue on homebrew which recommends adding the --compiler-flags
.
Installing libpng and setting the compiler flags didn't make the error go away, and in desperation I went into dlib/image_save/save_png.h
to comment out the assert. However, there was a helpful commend in the code:
#ifndef DLIB_PNG_SUPPORT
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
You are getting this error because you are trying to use save_png()
but you haven't defined DLIB_PNG_SUPPORT. You must do so to use
this function. You must also make sure you set your build environment
to link against the libpng library.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
COMPILE_TIME_ASSERT(sizeof(image_type) == 0);
#else
...
Given that I have libpng, I set DLIB_PNG_SUPPORT and building succeeded.
Then ensure your virtual environment is active (if applicable) and install it:
python -m pip install .
Should work if you force a reinstall using:
pip3 install dlib --force-reinstall --no-cache-dir --global-option=build_ext
That fixed it for me.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.