日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

pip install dlib報C++11 is required to use dlib

作者:修煉之路 更新時間: 2022-02-13 編程語言

錯誤原因

在使用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.

原因分析

從錯誤信息上來看是由于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,而默認使用的正是這個版本,所以導致出錯了。

解決辦法

  • 改變conda環境下的gcc版本
  1. 查看conda環境下的gcc版本
gcc --version或gcc -v
  1. 替換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
  1. 導入環境變量
#激活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

參考

  1. https://www.zhihu.com/question/56272908
  2. https://github.com/ContinuumIO/anaconda-issues/issues/8729
  3. https://github.com/pySTEPS/pysteps/issues/37

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

欄目分類
最近更新