Windows10 Python3.6环境安装face_recognition模块时dlib安装报错
Windows 10 Python3.6安装face_recognition dlib依赖报错处理
错误日志
Using legacy 'setup.py install' for dlib, since package 'wheel' is not installed. Installing collected packages: dlib, Click, face-recognition Running setup.py install for dlib ... error ERROR: Command errored out with exit status 1: command: 'c:\users\acer\appdata\local\programs\python\python36-32\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\acer\\AppData\\Local\\Temp\\pip-install-cljzfpu6\\dlib_351488587aea427493530fa6c8e1bf03\\setup.py'"'"'; __file__='"'"'C:\\Users\\acer\\AppData\\Local\\Temp\\pip-install-cljzfpu6\\dlib_351488587aea427493530fa6c8e1bf03\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\acer\AppData\Local\Temp\pip-record-3ig35xio\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\acer\appdata\local\programs\python\python36-32\Include\dlib' cwd: C:\Users\acer\AppData\Local\Temp\pip-install-cljzfpu6\dlib_351488587aea427493530fa6c8e1bf03\ Complete output (59 lines): running install c:\users\acer\appdata\local\programs\python\python36-32\lib\site-packages\setuptools\command\install.py:37: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. setuptools.SetuptoolsDeprecationWarning, 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.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] Invoking CMake setup: 'cmake C:\Users\acer\AppData\Local\Temp\pip-install-cljzfpu6\dlib_351488587aea427493530fa6c8e1bf03\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\acer\AppData\Local\Temp\pip-install-cljzfpu6\dlib_351488587aea427493530fa6c8e1bf03\build\lib.win32-3.6 -DPYTHON_EXECUTABLE=c:\users\acer\appdata\local\programs\python\python36-32\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\acer\AppData\Local\Temp\pip-install-cljzfpu6\dlib_351488587aea427493530fa6c8e1bf03\build\lib.win32-3.6' -- Building for: Visual Studio 17 2022 -- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19043. -- The C compiler identification is unknown -- The CXX compiler identification is unknown CMake Error at CMakeLists.txt:14 (project): No CMAKE_C_COMPILER could be found. CMake Error at CMakeLists.txt:14 (project): No CMAKE_CXX_COMPILER could be found. -- Configuring incomplete, errors occurred! See also "C:/Users/acer/AppData/Local/Temp/pip-install-cljzfpu6/dlib_351488587aea427493530fa6c8e1bf03/build/temp.win32-3.6/Release/CMakeFiles/CMakeOutput.log". See also "C:/Users/acer/AppData/Local/Temp/pip-install-cljzfpu6/dlib_351488587aea427493530fa6c8e1bf03/build/temp.win32-3.6/Release/CMakeFiles/CMakeError.log". Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Users\acer\AppData\Local\Temp\pip-install-cljzfpu6\dlib_351488587aea427493530fa6c8e1bf03\setup.py", line 261, in <module> 'Topic :: Software Development', File "c:\users\acer\appdata\local\programs\python\python36-32\lib\site-packages\setuptools\__init__.py", line 159, in setup return distutils.core.setup(**attrs) File "c:\users\acer\appdata\local\programs\python\python36-32\lib\distutils\core.py", line 148, in setup dist.run_commands() File "c:\users\acer\appdata\local\programs\python\python36-32\lib\distutils\dist.py", line 955, in run_commands self.run_command(cmd) File "c:\users\acer\appdata\local\programs\python\python36-32\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "c:\users\acer\appdata\local\programs\python\python36-32\lib\site-packages\setuptools\command\install.py", line 68, in run return orig.install.run(self) File "c:\users\acer\appdata\local\programs\python\python36-32\lib\distutils\command\install.py", line 545, in run self.run_command('build') File "c:\users\acer\appdata\local\programs\python\python36-32\lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "c:\users\acer\appdata\local\programs\python\python36-32\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "c:\users\acer\appdata\local\programs\python\python36-32\lib\distutils\command\build.py", line 135, in run self.run_command(cmd_name) File "c:\users\acer\appdata\local\programs\python\python36-32\lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "c:\users\acer\appdata\local\programs\python\python36-32\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "C:\Users\acer\AppData\Local\Temp\pip-install-cljzfpu6\dlib_351488587aea427493530fa6c8e1bf03\setup.py", line 134, in run self.build_extension(ext) File "C:\Users\acer\AppData\Local\Temp\pip-install-cljzfpu6\dlib_351488587aea427493530fa6c8e1bf03\setup.py", line 171, in build_extension subprocess.check_call(cmake_setup, cwd=build_folder) File "c:\users\acer\appdata\local\programs\python\python36-32\lib\subprocess.py", line 291, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\acer\\AppData\\Local\\Temp\\pip-install-cljzfpu6\\dlib_351488587aea427493530fa6c8e1bf03\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\acer\\AppData\\Local\\Temp\\pip-install-cljzfpu6\\dlib_351488587aea427493530fa6c8e1bf03\\build\\lib.win32-3.6', '-DPYTHON_EXECUTABLE=c:\\users\\acer\\appdata\\local\\programs\\python\\python36-32\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\acer\\AppData\\Local\\Temp\\pip-install-cljzfpu6\\dlib_351488587aea427493530fa6c8e1bf03\\build\\lib.win32-3.6']' returned non-zero exit status 1. ---------------------------------------- ERROR: Command errored out with exit status 1: 'c:\users\acer\appdata\local\programs\python\python36-32\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\acer\\AppData\\Local\\Temp\\pip-install-cljzfpu6\\dlib_351488587aea427493530fa6c8e1bf03\\setup.py'"'"'; __file__='"'"'C:\\Users\\acer\\AppData\\Local\\Temp\\pip-install-cljzfpu6\\dlib_351488587aea427493530fa6c8e1bf03\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\acer\AppData\Local\Temp\pip-record-3ig35xio\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\acer\appdata\local\programs\python\python36-32\Include\dlib' Check the logs for full command output
错误原因
报错核心是dlib需要从源码编译安装,当前系统缺少必要的编译依赖:
- 未安装wheel包,pip默认使用旧版setup.py方式编译安装
- 系统缺少CMake工具,以及对应32位Python3.6的C/C编译工具链,CMake无法找到可用的C/C编译器导致编译终止
解决方法
方案1:安装预编译dlib包(操作最简单,无需配置编译环境)
- 第一步先安装wheel依赖:
pip install wheel - 下载适配32位Python3.6版本的dlib预编译whl安装包,存到本地任意目录
- 执行本地安装dlib命令,替换为你实际的包文件路径:
pip install C:\下载目录\dlib-19.22.0-cp36-cp36m-win32.whl - dlib安装完成后,再执行face_recognition安装命令:
pip install face_recognition
方案2:配置编译环境源码编译安装
- 先安装CMake工具:
pip install cmake - 打开Visual Studio Installer,安装使用C++的桌面开发工作负载,确保勾选对应版本的Windows SDK以及32位编译工具组件
- 重启命令行工具,重新执行安装命令:
pip install face_recognition
内容的提问来源于stack exchange,提问作者Mandalorian
相关产品推荐
相关产品推荐

