代码改变世界

Win10 和 Ubuntu 20.04 安装 face_recognition 和 dlib

2022-04-05 16:16  jym蒟蒻  阅读(922)  评论(0编辑  收藏  举报

face_recognition是一个人脸识别库。

WIN10安装:

首先改一下下载源:

1.C:\Users\xx\pip,新建文件pip.ini
2.文件里面输入:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com

然后安装vs2019

需要勾选c++那一项。

安装face_recognition步骤如下

命令行输入:

1.python -m pip install --upgrade pip
2.pip install cmake
3.pip install dlib
4.pip install face_recognition

报错原因及解决:

1.pip install dlib出现:


      You must use Visual Studio to build a python extension on windows.  If you
      are getting this error it means you have not installed Visual C++.  Note
      that there are many flavors of Visual Studio, like Visual Studio for C#
      development.  You need to install Visual Studio for C++.

说明没有安装Visual Studio

安装vs2019,勾选c++那一项进行安装即可解决。

2 . pip install dlib出现ERROR: CMake must be installed to build dlib

先进行pip install cmake再pip install dlib

Ubuntu 20.04安装

改下载源

mkdir ~/.pip            // 创建隐藏的文件夹(注意用户是root还是普通user)
vim ~/.pip/pip.conf     // 创建一个pip.conf文件
 
// 在pip.conf中粘贴进下面内容(豆瓣源)
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com
 
// wq保存一下就行了

然后终端输入:

CC=gcc
CXX=g++
pip install face_recognition

报错原因及解决:

Building wheels for collected packages: dlib
  Building wheel for dlib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-9n08rmx4/dlib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-9n08rmx4/dlib/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-ajvzzs1b
       cwd: /tmp/pip-install-9n08rmx4/dlib/
  Complete output (50 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.8.10 (default, Sep 28 2021, 16:10:42)
  Invoking CMake setup: 'cmake /tmp/pip-install-9n08rmx4/dlib/tools/python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-install-9n08rmx4/dlib/build/lib.linux-x86_64-3.8 -DPYTHON_EXECUTABLE=/usr/bin/python3 -DCMAKE_BUILD_TYPE=Release'
  CMake Error at /usr/share/cmake-3.16/Modules/CMakeDetermineCCompiler.cmake:49 (message):
    Could not find compiler set in environment variable CC:
  
    /usr/local/bin/gcc.
  Call Stack (most recent call first):
    CMakeLists.txt:14 (project)
  
  
  CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
  CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
  -- Configuring incomplete, errors occurred!
  See also "/tmp/pip-install-9n08rmx4/dlib/build/temp.linux-x86_64-3.8/CMakeFiles/CMakeOutput.log".
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-9n08rmx4/dlib/setup.py", line 222, in <module>
      setup(
    File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 144, in setup
      return distutils.core.setup(**attrs)
    File "/usr/lib/python3.8/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/usr/lib/python3.8/distutils/dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "/usr/lib/python3.8/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/usr/lib/python3/dist-packages/wheel/bdist_wheel.py", line 223, in run
      self.run_command('build')
    File "/usr/lib/python3.8/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/usr/lib/python3.8/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/usr/lib/python3.8/distutils/command/build.py", line 135, in run
      self.run_command(cmd_name)
    File "/usr/lib/python3.8/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/usr/lib/python3.8/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/tmp/pip-install-9n08rmx4/dlib/setup.py", line 134, in run
      self.build_extension(ext)
    File "/tmp/pip-install-9n08rmx4/dlib/setup.py", line 171, in build_extension
      subprocess.check_call(cmake_setup, cwd=build_folder)
    File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['cmake', '/tmp/pip-install-9n08rmx4/dlib/tools/python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-install-9n08rmx4/dlib/build/lib.linux-x86_64-3.8', '-DPYTHON_EXECUTABLE=/usr/bin/python3', '-DCMAKE_BUILD_TYPE=Release']' returned non-zero exit status 1.
  ----------------------------------------
  ERROR: Failed building wheel for dlib
  Running setup.py clean for dlib
Failed to build dlib
Installing collected packages: face-recognition-models, dlib, face-recognition
    Running setup.py install for dlib ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-9n08rmx4/dlib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-9n08rmx4/dlib/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-476x_oyc/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/jym/.local/include/python3.8/dlib
         cwd: /tmp/pip-install-9n08rmx4/dlib/
    Complete output (52 lines):
    running install
    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.8.10 (default, Sep 28 2021, 16:10:42)
    Invoking CMake setup: 'cmake /tmp/pip-install-9n08rmx4/dlib/tools/python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-install-9n08rmx4/dlib/build/lib.linux-x86_64-3.8 -DPYTHON_EXECUTABLE=/usr/bin/python3 -DCMAKE_BUILD_TYPE=Release'
    CMake Error at /usr/share/cmake-3.16/Modules/CMakeDetermineCCompiler.cmake:49 (message):
      Could not find compiler set in environment variable CC:
    
      /usr/local/bin/gcc.
    Call Stack (most recent call first):
      CMakeLists.txt:14 (project)
    
    
    CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
    CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
    -- Configuring incomplete, errors occurred!
    See also "/tmp/pip-install-9n08rmx4/dlib/build/temp.linux-x86_64-3.8/CMakeFiles/CMakeOutput.log".
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-9n08rmx4/dlib/setup.py", line 222, in <module>
        setup(
      File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 144, in setup
        return distutils.core.setup(**attrs)
      File "/usr/lib/python3.8/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/lib/python3.8/distutils/dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "/usr/lib/python3.8/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/usr/lib/python3/dist-packages/setuptools/command/install.py", line 61, in run
        return orig.install.run(self)
      File "/usr/lib/python3.8/distutils/command/install.py", line 589, in run
        self.run_command('build')
      File "/usr/lib/python3.8/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python3.8/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/usr/lib/python3.8/distutils/command/build.py", line 135, in run
        self.run_command(cmd_name)
      File "/usr/lib/python3.8/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/lib/python3.8/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/tmp/pip-install-9n08rmx4/dlib/setup.py", line 134, in run
        self.build_extension(ext)
      File "/tmp/pip-install-9n08rmx4/dlib/setup.py", line 171, in build_extension
        subprocess.check_call(cmake_setup, cwd=build_folder)
      File "/usr/lib/python3.8/subprocess.py", line 364, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['cmake', '/tmp/pip-install-9n08rmx4/dlib/tools/python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-install-9n08rmx4/dlib/build/lib.linux-x86_64-3.8', '-DPYTHON_EXECUTABLE=/usr/bin/python3', '-DCMAKE_BUILD_TYPE=Release']' returned non-zero exit status 1.
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-9n08rmx4/dlib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-9n08rmx4/dlib/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-476x_oyc/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/jym/.local/include/python3.8/dlib Check the logs for full command output.

在终端输入:

CC=gcc
CXX=g++

再进行pip install face_recognition就可以了