解决pip install dlib报错C++11 is required to use dlib

解决pip install dlib报错C++11 is required to use dlib

目录

1.错误原因

2.原因分析

3.解决办法

1.错误原因

在使用pip install dlib安装dlib的时候报错,

错误的详细信息如下:

ERROR: Command errored out with exit status 1:
command: /root/miniconda3/envs/cv_1/bin/python -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"’/tmp/pip-install-jpjqw_8i/dlib_a6680215d7d4421581b7b4999664056c/setup.py’"’"’; file=’"’"’/tmp/pip-install-jpjqw_8i/dlib_a6680215d7d4421581b7b4999664056c/setup.py’"’"’;f=getattr(tokenize, ‘"’"‘open’"’"’, open)(file);code=f.read().replace(’"’"’\r\n’"’"’, ‘"’"’\n’"’"’);f.close();exec(compile(code, file, ‘"’"‘exec’"’"’))’ bdist_wheel -d /tmp/pip-wheel-pi50j_zu
cwd: /tmp/pip-install-jpjqw_8i/dlib_a6680215d7d4421581b7b4999664056c/
Complete output (76 lines):
running bdist_wheel
running build
running build_py
package init file ‘tools/python/dlib/init.py’ not found (or not a regular file)
running build_ext
Building extension for Python 3.6.13 |Anaconda, Inc.| (default, Jun 4 2021, 14:25:59)
Invoking CMake setup: ‘cmake /tmp/pip-install-jpjqw_8i/dlib_a6680215d7d4421581b7b4999664056c/tools/python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-install-jpjqw_8i/dlib_a6680215d7d4421581b7b4999664056c/build/lib.linux-x86_64-3.6 -DPYTHON_EXECUTABLE=/root/miniconda3/envs/cv_1/bin/python -DCMAKE_BUILD_TYPE=Release’
– The C compiler identification is GNU 11.2.0
– The CXX compiler identification is GNU 4.8.5
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Check for working C compiler: /usr/bin/cc - skipped
– Detecting C compile features
– Detecting C compile features - done
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Check for working CXX compiler: /usr/bin/c++ - skipped
– Detecting CXX compile features
– Detecting CXX compile features - done
– Found PythonInterp: /root/miniconda3/envs/cv_1/bin/python (found version “3.6.13”)
– Found PythonLibs: /root/miniconda3/envs/cv_1/lib/libpython3.6m.so
– Performing Test HAS_CPP14_FLAG
– Performing Test HAS_CPP14_FLAG - Failed
– Performing Test HAS_CPP11_FLAG
– Performing Test HAS_CPP11_FLAG - Success
– pybind11 v2.2.4
– Using CMake version: 3.21.2
– Compiling dlib version: 19.23.0
CMake Error at /tmp/pip-install-jpjqw_8i/dlib_a6680215d7d4421581b7b4999664056c/dlib/cmake_utils/set_compiler_specific_options.cmake:50 (message):
C++11 is required to use dlib, but the version of GCC you are using is too
old and doesn’t support C++11. You need GCC 4.9 or newer.
Call Stack (most recent call first):
/tmp/pip-install-jpjqw_8i/dlib_a6680215d7d4421581b7b4999664056c/dlib/cmake_utils/test_for_sse4/CMakeLists.txt:8 (include)

接下来我们找错误提示的重点信息:

C++11 is required to use dlib, but the version of GCC you are using is too
old and doesn’t support C++11. You need GCC 4.9 or newer.

2.原因分析

从错误信息上来看是由于gcc的版本低于4.9导致无法支持C++ 11,查看gcc的版本

#查看gcc的版本信息 gcc --version :' gcc (GCC) 11.2.0 Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. '

从输出的gcc版本信息来看,不应该出错呀,因为gcc的版本已经大于4.9了。

出错的原因在于安装dlib的时候使用了conda的虚拟环境,而在环境内有一个低于4.9的gcc,而默认使用的正是这个版本,所以导致出错了。

3.解决办法

改变conda环境下的gcc版本:

1.查看conda环境下的gcc版本

gcc --version或gcc -v

2.替换gcc的版本

利用软连接来覆盖conda环境下的gcc版本

命令如下:

ln -s /usr/local/bin/gcc /home/name/anconda3/envs/env_name/bin/gcc

找不到conda中安装的gcc:

我就属于这种情况,在conda中找不到任何关于gcc的信息,在conda环境下使用gcc -v输出的版本也和没有使用conda环境输出的版本信息一致。

1.找到gcc的安装位置

which gcc #/usr/local/bin/gcc

2.导入环境变量

#激活conda环境 source activate cv #设置环境变量 export CC=/usr/local/bin/gcc

终极解决办法:

在环境外编译dlib的源码,生成whl文件,然后再环境内通过whl文件来安装dlib,

步骤如下:

#clone dlib的源码 git clone https://github.com/davisking/dlib.git #编译dlib mkdir build; cd build; cmake .. ; cmake --build . #安装python版本的dlib python setup.py install

到此这篇关于pip install dlib报错C++11 is required to use dlib的文章就介绍到这了,更多相关报错C++11 is required to use dlib内容请搜索易知道(ezd.cc)以前的文章或继续浏览下面的相关文章希望大家以后多多支持易知道(ezd.cc)!

推荐阅读