广告
返回顶部
首页 > 资讯 > 后端开发 > 其他教程 >解决pip install dlib报错C++11 is required to use dlib
  • 190
分享到

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

2024-04-02 19:04:59 190人浏览 独家记忆
摘要

目录1.错误原因2.原因分析3.解决办法1.错误原因 在使用pip install dlib安装dlib的时候报错, 错误的详细信息如下: ERROR: Command errore

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内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: 解决pip install dlib报错C++11 is required to use dlib

本文链接: https://www.lsjlt.com/news/138369.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作