PR

face_recognition をインストールすると「dlib」エラーが!!

スポンサーリンク
この記事は約23分で読めます。
環境
Python3.7
windows10

 

face_recognitionのインストールすると
あらまぁ!「Building wheel for dlib (setup.py) … error」を文頭に連続のエラーが!!
調べるのに1日半もかかったので、備忘録です。

何故インストールできないのか?【結論】

dlib」はC++のlibraryだから、Python単体のインストールのみではインストールできないらしい

出力されたエラーからは dlibのwheelが構築されずにエラーになっていると記載されている。

↓以下は出力されたエラーの翻訳↓

dlibのビルドホイール(setup.py)...エラー

 


Building wheel for dlib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\user\Anaconda3\envs\face_test\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\user\\AppData\\Local\\Temp\\pip-install-f3b16jyg\\dlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\user\\AppData\\Local\\Temp\\pip-install-f3b16jyg\\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\user\AppData\Local\Temp\pip-wheel-i8npmpmg'
       cwd: C:\Users\user\AppData\Local\Temp\pip-install-f3b16jyg\dlib\
  Complete output (55 lines):
  running bdist_wheel
  running build
  running build_py
  package init file 'dlib\__init__.py' not found (or not a regular file)
  running build_ext
  Building extension for Python 3.7.7 (default, May  9 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)]
  Invoking CMake setup: 'cmake C:\Users\user\AppData\Local\Temp\pip-install-f3b16jyg\dlib\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\user\AppData\Local\Temp\pip-install-f3b16jyg\dlib\build\lib.win-amd64-3.7 -DPYTHON_EXECUTABLE=C:\Users\user\Anaconda3\envs\face_test\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\user\AppData\Local\Temp\pip-install-f3b16jyg\dlib\build\lib.win-amd64-3.7 -A x64'
  -- Building for: NMake Makefiles
  CMake Error at CMakeLists.txt:3 (project):
    Generator
 
      NMake Makefiles
 
    does not support platform specification, but platform
 
      x64
 
    was specified.
 
 
  CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
  CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
  -- Configuring incomplete, errors occurred!
  See also "C:/Users/user/AppData/Local/Temp/pip-install-f3b16jyg/dlib/build/temp.win-amd64-3.7/Release/CMakeFiles/CMakeOutput.log".
  Traceback (most recent call last):
    File "", line 1, in 
    File "C:\Users\user\AppData\Local\Temp\pip-install-f3b16jyg\dlib\setup.py", line 261, in 
      'Topic :: Software Development',
    File "C:\Users\user\Anaconda3\envs\face_test\lib\site-packages\setuptools\__init__.py", line 144, in setup
      return distutils.core.setup(**attrs)
    File "C:\Users\user\Anaconda3\envs\face_test\lib\distutils\core.py", line 148, in setup
      dist.run_commands()
    File "C:\Users\user\Anaconda3\envs\face_test\lib\distutils\dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "C:\Users\user\Anaconda3\envs\face_test\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\user\Anaconda3\envs\face_test\lib\site-packages\wheel\bdist_wheel.py", line 223, in run
      self.run_command('build')
    File "C:\Users\user\Anaconda3\envs\face_test\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "C:\Users\user\Anaconda3\envs\face_test\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\user\Anaconda3\envs\face_test\lib\distutils\command\build.py", line 135, in run
      self.run_command(cmd_name)
    File "C:\Users\user\Anaconda3\envs\face_test\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "C:\Users\user\Anaconda3\envs\face_test\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\user\AppData\Local\Temp\pip-install-f3b16jyg\dlib\setup.py", line 135, in run
      self.build_extension(ext)
    File "C:\Users\user\AppData\Local\Temp\pip-install-f3b16jyg\dlib\setup.py", line 172, in build_extension
      subprocess.check_call(cmake_setup, cwd=build_folder)
    File "C:\Users\user\Anaconda3\envs\face_test\lib\subprocess.py", line 363, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\user\\AppData\\Local\\Temp\\pip-install-f3b16jyg\\dlib\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\user\\AppData\\Local\\Temp\\pip-install-f3b16jyg\\dlib\\build\\lib.win-amd64-3.7', '-DPYTHON_EXECUTABLE=C:\\Users\\user\\Anaconda3\\envs\\face_test\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\user\\AppData\\Local\\Temp\\pip-install-f3b16jyg\\dlib\\build\\lib.win-amd64-3.7', '-A', 'x64']' 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, Pillow, dlib, Click, face-recognition
    Running setup.py install for dlib ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\user\Anaconda3\envs\face_test\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\user\\AppData\\Local\\Temp\\pip-install-f3b16jyg\\dlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\user\\AppData\\Local\\Temp\\pip-install-f3b16jyg\\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\user\AppData\Local\Temp\pip-record-rrnx1meu\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\user\Anaconda3\envs\face_test\Include\dlib'
         cwd: C:\Users\user\AppData\Local\Temp\pip-install-f3b16jyg\dlib\
    Complete output (57 lines):
    running install
    running build
    running build_py
    package init file 'dlib\__init__.py' not found (or not a regular file)
    running build_ext
    Building extension for Python 3.7.4 (default, August  6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)]
    Invoking CMake setup: 'cmake C:\Users\user\AppData\Local\Temp\pip-install-f3b16jyg\dlib\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\user\AppData\Local\Temp\pip-install-f3b16jyg\dlib\build\lib.win-amd64-3.7 -DPYTHON_EXECUTABLE=C:\Users\user\Anaconda3\envs\face_test\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\user\AppData\Local\Temp\pip-install-f3b16jyg\dlib\build\lib.win-amd64-3.7 -A x64'
    -- Building for: NMake Makefiles
    CMake Error at CMakeLists.txt:3 (project):
      Generator
 
        NMake Makefiles
 
      does not support platform specification, but platform
 
        x64
 
      was specified.
 
 
    CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
    CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
    -- Configuring incomplete, errors occurred!
    See also "C:/Users/user/AppData/Local/Temp/pip-install-f3b16jyg/dlib/build/temp.win-amd64-3.7/Release/CMakeFiles/CMakeOutput.log".
    Traceback (most recent call last):
      File "", line 1, in 
      File "C:\Users\user\AppData\Local\Temp\pip-install-f3b16jyg\dlib\setup.py", line 261, in 
        'Topic :: Software Development',
      File "C:\Users\user\Anaconda3\envs\face_test\lib\site-packages\setuptools\__init__.py", line 144, in setup
        return distutils.core.setup(**attrs)
      File "C:\Users\user\Anaconda3\envs\face_test\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "C:\Users\user\Anaconda3\envs\face_test\lib\distutils\dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "C:\Users\user\Anaconda3\envs\face_test\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\user\Anaconda3\envs\face_test\lib\site-packages\setuptools\command\install.py", line 61, in run
        return orig.install.run(self)
      File "C:\Users\user\Anaconda3\envs\face_test\lib\distutils\command\install.py", line 545, in run
        self.run_command('build')
      File "C:\Users\user\Anaconda3\envs\face_test\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "C:\Users\user\Anaconda3\envs\face_test\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\user\Anaconda3\envs\face_test\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "C:\Users\user\Anaconda3\envs\face_test\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "C:\Users\user\Anaconda3\envs\face_test\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\user\AppData\Local\Temp\pip-install-f3b16jyg\dlib\setup.py", line 135, in run
        self.build_extension(ext)
      File "C:\Users\user\AppData\Local\Temp\pip-install-f3b16jyg\dlib\setup.py", line 172, in build_extension
        subprocess.check_call(cmake_setup, cwd=build_folder)
      File "C:\Users\user\Anaconda3\envs\face_test\lib\subprocess.py", line 363, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\user\\AppData\\Local\\Temp\\pip-install-f3b16jyg\\dlib\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\user\\AppData\\Local\\Temp\\pip-install-f3b16jyg\\dlib\\build\\lib.win-amd64-3.7', '-DPYTHON_EXECUTABLE=C:\\Users\\user\\Anaconda3\\envs\\face_test\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\user\\AppData\\Local\\Temp\\pip-install-f3b16jyg\\dlib\\build\\lib.win-amd64-3.7', '-A', 'x64']' returned non-zero exit status 1.
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\user\Anaconda3\envs\face_test\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\user\\AppData\\Local\\Temp\\pip-install-f3b16jyg\\dlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\user\\AppData\\Local\\Temp\\pip-install-f3b16jyg\\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\user\AppData\Local\Temp\pip-record-rrnx1meu\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\user\Anaconda3\envs\face_test\Include\dlib' Check the logs for full command output.

解決方法

Visual Studio Community Editionが未インストールの場合

Visual Studio Community Editionをインストール後、

初期表示される開発環境から【C++によるデスクトップ開発】をインストールします。

前提条件として以下の条件が整えば簡単にインストールできるようです。
Python 3.5
Visual Studio Community Edition
参考サイト Windows での Python 2.7, 3.4, 3.5 の拡張モジュールビルド環境

※ちなみに以下の組み合わせでもOKでした。
Python3.7&Visual Studio Community Edition2017
Python3.8&Visual Studio Community Edition2019

Visual Studio Community Editionをインストール済の場合

スタート>>Visual Studio Installerから

変更をクリックします

C++によるデスクトップ開発を選択しインストールするとC++のツールが一緒にインストールされます

face_recognitionインストールする

PyCharmのterminalから pip install face_recognition で、無事インストール完了。

(base) C:\Users\user\PycharmProjects\ discrimination>pip install face_recognition
Collecting face_recognition
  Downloading https://files.pythonhosted.org/packages/1e/95/f6c9330f54ab07bfa032bf3715c12455a381083125d8880c43cbe76bb3d0/face_recognition-1.3.0-py2.py3-none-any.whl
Collecting dlib>=19.7 (from face_recognition)
  Downloading https://files.pythonhosted.org/packages/f1/40/e407366816646bb452578997e6ca2140f004eec8f611e8512ee429ded2be/dlib-19.20.0.tar.gz (3.2MB)
     |████████████████████████████████| 3.2MB 3.2MB/s
Requirement already satisfied: Click>=6.0 in c:\users\user\anaconda3\lib\site-packages (from face_recognition) (7.0)
Requirement already satisfied: Pillow in c:\users\user\anaconda3\lib\site-packages (from face_recognition) (6.2.0)
Collecting face-recognition-models>=0.3.0 (from face_recognition)
  Downloading https://files.pythonhosted.org/packages/cf/3b/4fd8c534f6c0d1b80ce0973d01331525538045084c73c153ee6df20224cf/face_recognition_models-0.3.0.tar.gz (100.1MB)
     |████████████████████████████████| 100.2MB 6.4MB/s
Requirement already satisfied: numpy in c:\users\user\anaconda3\lib\site-packages (from face_recognition) (1.16.5)
Building wheels for collected packages: dlib, face-recognition-models
  Building wheel for dlib (setup.py) ... done
  Created wheel for dlib: filename=dlib-19.20.0-cp37-cp37m-win_amd64.whl size=3172188 sha256=f5330583fdab3673cd60987f2a0c1330ca5ec68078457931169d758040a9e847
  Stored in directory: C:\Users\user\AppData\Local\pip\Cache\wheels\cf\ef\5c\264d6a760f15e39ca65b749b095c7cfdbafbc5adf915178c1b
  Building wheel for face-recognition-models (setup.py) ... done
  Created wheel for face-recognition-models: filename=face_recognition_models-0.3.0-py2.py3-none-any.whl size=100566178 sha256=fdc9e289afa547b8f07ee207d9ee57cdecf4508e7573d163b4b31c2ab09c1
1bc
  Stored in directory: C:\Users\user\AppData\Local\pip\Cache\wheels\d2\99\18\59c6c8f01e39810415c0e63f5bede7d83dfb0ffc039865465f
Successfully built dlib face-recognition-models
Installing collected packages: dlib, face-recognition-models, face-recognition
Successfully installed dlib-19.20.0 face-recognition-1.3.0 face-recognition-models-0.3.0

(base) C:\Users\user\PycharmProjects\ discrimination>

コメント

タイトルとURLをコピーしました