执行pip install face_recognition时dlib编译失败问题求助
安装face_recognition时dlib编译失败的解决方案
问题描述
在PyCharm环境下执行pip install face_recognition安装face_recognition库时,出现编译dlib失败的错误,已提前安装cmake,单独安装dlib也遇到同类错误。
错误摘要
ERROR : Could not build wheels for dlib, which is required to install pyproject.toml-based projects
完整错误信息
Whole Error : Building wheel for dlib (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for dlib (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [314 lines of output] running bdist_wheel running build running build_ext Building extension for Python 3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)] Invoking CMake setup: 'cmake C:\Users\Shashwat\AppData\Local\Temp\pip-install-gem29hzl\dlib_bd69ef4fa75e4a58a152da24ab42b4d5\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\Shashwat\AppData\Local\Temp\pip-install-gem29hzl\dlib_bd69ef4fa75e4a58a152da24ab42b4d5\build\lib.win-amd64-cpython-38 -DPYTHON_EXECUTABLE=C:\ProgramData\Anaconda3\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\Shashwat\AppData\Local\Temp\pip-install-gem29hzl\dlib_bd69ef4fa75e4a58a152da24ab42b4d5\build\lib.win-amd64-cpython-38 -A x64' -- Building for: Visual Studio 17 2022 -- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.22621. -- The C compiler identification is MSVC 19.36.32534.0 -- The CXX compiler identification is MSVC 19.36.32534.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - 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: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- pybind11 v2.10.0 -- Found PythonInterp: C:/ProgramData/Anaconda3/python.exe (found suitable version "3.8.8", minimum required is "3.6") -- Found PythonLibs: C:/ProgramData/Anaconda3/libs/python38.lib -- Performing Test HAS_MSVC_GL_LTCG -- Performing Test HAS_MSVC_GL_LTCG - Success -- Using CMake version: 3.26.4 -- Compiling dlib version: 19.24.2 -- Looking for sys/types.h -- Looking for sys/types.h - found -- Looking for stdint.h -- Looking for stdint.h - found -- Looking for stddef.h -- Looking for stddef.h - found -- Check size of void* -- Check size of void* - done -- Enabling SSE2 instructions -- Searching for BLAS and LAPACK -- Searching for BLAS and LAPACK -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - not found -- Found Threads: TRUE CUDA_TOOLKIT_ROOT_DIR not found or specified -- Could NOT find CUDA (missing: CUDA_TOOLKIT_ROOT_DIR CUDA_NVCC_EXECUTABLE CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY) (Required is at least version "7.5") -- Found CUDA, but CMake was unable to find the cuBLAS libraries that should be part of every basic CUDA install. Your CUDA install is somehow broken or incomplete. Since cuBLAS is required for dlib to use CUDA we won't use CUDA. -- DID NOT FIND CUDA -- Disabling CUDA support for dlib. DLIB WILL NOT USE CUDA -- Searching for FFMPEG/LIBAV -- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) -- PkgConfig could not be found, FFMPEG won't be available -- Configuring done (80.0s) -- Generating done (0.1s) -- Build files have been written to: C:/Users/Shashwat/AppData/Local/Temp/pip-install-gem29hzl/dlib_bd69ef4fa75e4a58a152da24ab42b4d5/build/temp.win-amd64-cpython-38/Release Invoking CMake build: 'cmake --build . --config Release -- /m' MSBuild version 17.6.3+07e294721 for .NET Framework note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for dlib Failed to build dlib ERROR: Could not build wheels for dlib, which is required to install pyproject.toml-based projects
解决方案
方法1:安装预编译的dlib wheel包
Windows环境下直接编译dlib容易出问题,优先使用官方预编译包:
- 打开PyCharm终端或系统CMD,执行:
pip install dlib==19.24.2 - 若上述命令仍失败,手动下载对应Python版本的wheel文件(比如Python3.8 64位对应
dlib-19.24.2-cp38-cp38-win_amd64.whl),然后执行:pip install 下载的wheel文件完整路径 - 安装完成后,再执行
pip install face_recognition即可。
方法2:补全Visual Studio编译环境
如果必须编译源码,确保Visual Studio环境完整:
- 打开Visual Studio Installer,勾选**「Desktop development with C++」**组件,包含MSVC编译器、Windows SDK等必要工具,安装完成后重启电脑。
- 以管理员身份打开PyCharm终端,重新执行
pip install dlib或pip install face_recognition。
方法3:通过Anaconda安装dlib
利用conda的预编译包跳过编译步骤:
- 执行:
conda install -c conda-forge dlib - 安装完成后,再执行
pip install face_recognition。
内容的提问来源于stack exchange,提问作者Shashwat Shrivastava
相关产品推荐
相关产品推荐

