服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - C/C++ - 解决pip install dlib报错C++11 is required to use dlib

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

2022-09-14 15:58修炼之路 C/C++

这篇文章主要介绍了在使用pip install dlib安装dlib的时候报错C++11 is required to use dlib的解决方法,需要的的小伙伴可以参考一下,希望对你有所帮助

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的版本

?
1
2
3
4
5
6
7
8
#查看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版本

?
1
gcc --version或gcc -v

2.替换gcc的版本

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

命令如下:

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

找不到conda中安装的gcc:

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

1.找到gcc的安装位置

?
1
2
which gcc
#/usr/local/bin/gcc

2.导入环境变量

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

终极解决办法:

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

步骤如下:

?
1
2
3
4
5
6
#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内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://xiulian.blog.csdn.net/article/details/122740101

延伸 · 阅读

精彩推荐
  • C/C++C语言 位段的详细介绍

    C语言 位段的详细介绍

    这篇文章主要介绍了C语言 位段的详细介绍的相关资料,学习C语言基础的朋友,可以参考本文,需要的朋友可以参考下...

    海 子9602021-04-20
  • C/C++C语言 TerminateProcess函数案例详解

    C语言 TerminateProcess函数案例详解

    这篇文章主要介绍了C语言 TerminateProcess函数案例详解,本篇文章通过简要的案例,讲解了该项技术的了解与使用,以下就是详细内容,需要的朋友可以参考下...

    Giser_D10092021-12-20
  • C/C++C语言将24小时制转换为12小时制的方法

    C语言将24小时制转换为12小时制的方法

    这篇文章主要介绍了C语言将24小时制转换为12小时制的方法,涉及C语言针对时间的相关操作技巧,非常简单实用,需要的朋友可以参考下...

    defias10482021-03-01
  • C/C++冒泡算法的改进具体实现

    冒泡算法的改进具体实现

    这篇文章主要介绍了冒泡算法的改进具体实现,有需要的朋友可以参考一下...

    C语言教程网6242021-01-12
  • C/C++浅谈c++11线程的互斥量

    浅谈c++11线程的互斥量

    互斥量是个类对象,理解成一把锁(保护共享数据,其他想操作共享数据的线程必须等待解锁),互斥量使用要小心,保护数据不多也不少,少了则没达到...

    lsgxeva8052021-11-14
  • C/C++C经典算法之二分查找法

    C经典算法之二分查找法

    这篇文章主要介绍了C经典算法之二分查找法的相关资料,这里提供两种方法帮助大家实现这样的功能,需要的朋友可以参考下...

    CharlinGod4842021-06-04
  • C/C++用C++实现一个链式栈的实例代码

    用C++实现一个链式栈的实例代码

    本篇文章是对使用C++实现一个链式栈的代码进行了详细的分析介绍,需要的朋友参考下...

    C++教程网1782020-12-13
  • C/C++c++中explicit与mutable关键字的深入探究

    c++中explicit与mutable关键字的深入探究

    这篇文章主要给大家介绍了关于c++中explicit与mutable关键字的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值...

    cpp加油站4162021-11-05