在 Windows 中安装 DLIB、TensorFlow 和人脸识别错误

Posted

技术标签:

【中文标题】在 Windows 中安装 DLIB、TensorFlow 和人脸识别错误【英文标题】:Installing DLIB , TensorFlow and Face-Recognition error in Windows 【发布时间】:2021-02-18 05:16:06 【问题描述】:
C:\WINDOWS\system32>pip install face-recognition
Collecting face-recognition
  Using cached face_recognition-1.3.0-py2.py3-none-any.whl (15 kB)
Requirement already satisfied: numpy in c:\users\dell\appdata\local\programs\python\python38-32\lib\site-packages (from face-recognition) (1.19.1)
Requirement already satisfied: face-recognition-models>=0.3.0 in c:\users\dell\appdata\local\programs\python\python38-32\lib\site-packages (from face-recognition) (0.3.0)
Requirement already satisfied: Pillow in c:\users\dell\appdata\local\programs\python\python38-32\lib\site-packages (from face-recognition) (7.2.0)
Collecting dlib>=19.7
  Using cached dlib-19.21.0.tar.gz (3.2 MB)
Requirement already satisfied: Click>=6.0 in c:\users\dell\appdata\local\programs\python\python38-32\lib\site-packages (from face-recognition) (7.1.2)
Building wheels for collected packages: dlib
  Building wheel for dlib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\dell\appdata\local\programs\python\python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ffmft1wf\\dlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ffmft1wf\\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 'C:\Users\DELL\AppData\Local\Temp\pip-wheel-xf9e0i7s'
       cwd: C:\Users\DELL\AppData\Local\Temp\pip-install-ffmft1wf\dlib\
  Complete output (58 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.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)]
  Invoking CMake setup: 'cmake C:\Users\DELL\AppData\Local\Temp\pip-install-ffmft1wf\dlib\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\DELL\AppData\Local\Temp\pip-install-ffmft1wf\dlib\build\lib.win32-3.8 -DPYTHON_EXECUTABLE=c:\users\dell\appdata\local\programs\python\python38-32\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\DELL\AppData\Local\Temp\pip-install-ffmft1wf\dlib\build\lib.win32-3.8'
  -- Building for: NMake Makefiles
  CMake Error at CMakeLists.txt:5 (message):



    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


    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++.


    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!




  -- Configuring incomplete, errors occurred!
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\DELL\AppData\Local\Temp\pip-install-ffmft1wf\dlib\setup.py", line 223, in <module>
      setup(
    File "c:\users\dell\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\__init__.py", line 153, in setup
      return distutils.core.setup(**attrs)
    File "c:\users\dell\appdata\local\programs\python\python38-32\lib\distutils\core.py", line 148, in setup
      dist.run_commands()
    File "c:\users\dell\appdata\local\programs\python\python38-32\lib\distutils\dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "c:\users\dell\appdata\local\programs\python\python38-32\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "c:\users\dell\appdata\local\programs\python\python38-32\lib\site-packages\wheel\bdist_wheel.py", line 290, in run
      self.run_command('build')
    File "c:\users\dell\appdata\local\programs\python\python38-32\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "c:\users\dell\appdata\local\programs\python\python38-32\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "c:\users\dell\appdata\local\programs\python\python38-32\lib\distutils\command\build.py", line 135, in run
      self.run_command(cmd_name)
    File "c:\users\dell\appdata\local\programs\python\python38-32\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "c:\users\dell\appdata\local\programs\python\python38-32\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\DELL\AppData\Local\Temp\pip-install-ffmft1wf\dlib\setup.py", line 135, in run
      self.build_extension(ext)
    File "C:\Users\DELL\AppData\Local\Temp\pip-install-ffmft1wf\dlib\setup.py", line 172, in build_extension
      subprocess.check_call(cmake_setup, cwd=build_folder)
    File "c:\users\dell\appdata\local\programs\python\python38-32\lib\subprocess.py", line 364, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ffmft1wf\\dlib\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ffmft1wf\\dlib\\build\\lib.win32-3.8', '-DPYTHON_EXECUTABLE=c:\\users\\dell\\appdata\\local\\programs\\python\\python38-32\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ffmft1wf\\dlib\\build\\lib.win32-3.8']' 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: dlib, face-recognition
    Running setup.py install for dlib ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\dell\appdata\local\programs\python\python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ffmft1wf\\dlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ffmft1wf\\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 'C:\Users\DELL\AppData\Local\Temp\pip-record-k_fgj9zq\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\dell\appdata\local\programs\python\python38-32\Include\dlib'
         cwd: C:\Users\DELL\AppData\Local\Temp\pip-install-ffmft1wf\dlib\
    Complete output (60 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.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)]
    Invoking CMake setup: 'cmake C:\Users\DELL\AppData\Local\Temp\pip-install-ffmft1wf\dlib\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\DELL\AppData\Local\Temp\pip-install-ffmft1wf\dlib\build\lib.win32-3.8 -DPYTHON_EXECUTABLE=c:\users\dell\appdata\local\programs\python\python38-32\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\DELL\AppData\Local\Temp\pip-install-ffmft1wf\dlib\build\lib.win32-3.8'
    -- Building for: NMake Makefiles
    CMake Error at CMakeLists.txt:5 (message):



      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


      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++.


      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!




    -- Configuring incomplete, errors occurred!
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\DELL\AppData\Local\Temp\pip-install-ffmft1wf\dlib\setup.py", line 223, in <module>
        setup(
      File "c:\users\dell\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\__init__.py", line 153, in setup
        return distutils.core.setup(**attrs)
      File "c:\users\dell\appdata\local\programs\python\python38-32\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "c:\users\dell\appdata\local\programs\python\python38-32\lib\distutils\dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "c:\users\dell\appdata\local\programs\python\python38-32\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "c:\users\dell\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\command\install.py", line 61, in run
        return orig.install.run(self)
      File "c:\users\dell\appdata\local\programs\python\python38-32\lib\distutils\command\install.py", line 545, in run
        self.run_command('build')
      File "c:\users\dell\appdata\local\programs\python\python38-32\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "c:\users\dell\appdata\local\programs\python\python38-32\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "c:\users\dell\appdata\local\programs\python\python38-32\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "c:\users\dell\appdata\local\programs\python\python38-32\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "c:\users\dell\appdata\local\programs\python\python38-32\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\DELL\AppData\Local\Temp\pip-install-ffmft1wf\dlib\setup.py", line 135, in run
        self.build_extension(ext)
      File "C:\Users\DELL\AppData\Local\Temp\pip-install-ffmft1wf\dlib\setup.py", line 172, in build_extension
        subprocess.check_call(cmake_setup, cwd=build_folder)
      File "c:\users\dell\appdata\local\programs\python\python38-32\lib\subprocess.py", line 364, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ffmft1wf\\dlib\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ffmft1wf\\dlib\\build\\lib.win32-3.8', '-DPYTHON_EXECUTABLE=c:\\users\\dell\\appdata\\local\\programs\\python\\python38-32\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ffmft1wf\\dlib\\build\\lib.win32-3.8']' returned non-zero exit status 1.
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\dell\appdata\local\programs\python\python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ffmft1wf\\dlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\DELL\\AppData\\Local\\Temp\\pip-install-ffmft1wf\\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 'C:\Users\DELL\AppData\Local\Temp\pip-record-k_fgj9zq\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\dell\appdata\local\programs\python\python38-32\Include\dlib' Check the logs for full command output.

【问题讨论】:

【参考方案1】:

您尝试过这些步骤吗? Face-recognition on windows

这个包官方不支持windows,但是这个步骤可能对你有帮助。

另外一种方法是你可以在windows系统上下载它的带有虚拟盒子的环境。从这里pre-configured VM

我想它会帮助你。谢谢

【讨论】:

【参考方案2】:

为什么不采用 deepface 呢?它更轻巧,涵盖了基于 Keras 的面部识别模型。换句话说,它更容易安装和运行。

#!pip install deepface
from deepface import DeepFace
models = ["VGG-Face", "Facenet", "OpenFace", "DeepFace", "DeepID"]
res = DeepFace.verify("img1.jpg", "img2.jpg", model_name = models[0])

【讨论】:

以上是关于在 Windows 中安装 DLIB、TensorFlow 和人脸识别错误的主要内容,如果未能解决你的问题,请参考以下文章

在 anaconda 中安装 dlib 的错误

无法在 anaconda 中安装 dlib

在 Anaconda Python 中安装 Dlib

dlib 未在 pythonanywhere virtualenv 中安装

在 python 3.10 中安装 dlib 库时出错

在 Blender 的 Python 中安装 Dlib 时出错