[英]How to fix python `dlib` error: "symbol not found in flat namespace '_png_do_expand_palette_rgb8_neon'"?
I am getting the error: symbol not found in flat namespace '_png_do_expand_palette_rgb8_neon'
The error occurs in spite of the dlib
package being installed for the relevant Python version.我收到错误消息:
symbol not found in flat namespace '_png_do_expand_palette_rgb8_neon'
尽管为相关 Python 版本安装了dlib
package,但仍会发生错误。
I am using VSCode, in case that is relevant.我正在使用 VSCode,以防万一。
For me, this is a mac M1 specific issue, solved by linking libpng:对我来说,这是一个 mac M1 特定的问题,通过链接 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) (将 1.6.37 替换为您安装的 libpng 版本)
I ended up having to install dlib from source:我最终不得不从源代码安装 dlib:
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
.这是基于建议安装 libpng的 dlib 上的这个问题和建议添加
--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.安装 libpng 并设置编译器标志并没有使错误 go 消失,绝望中我进入
dlib/image_save/save_png.h
注释掉断言。 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.鉴于我有 libpng,我设置了 DLIB_PNG_SUPPORT 并成功构建。
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 pip3 install dlib --force-reinstall --no-cache-dir --global-option=build_ext
That fixed it for me.那为我修好了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.