You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu系统下Python安装dlib库失败问题求助

解决dlib安装时"CMake must be installed"错误

你执行pip install dlib时遇到的编译错误如下:

Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: dlib
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
╰─> [6 lines of output]
running bdist_wheel
running build
running build_ext

ERROR: CMake must be installed to build dlib
  
  [end of output]

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

下面是几种可行的解决方法:

  • 确认CMake已加入系统环境变量
    用pip install cmake安装的CMake可能未自动添加到系统PATH中。找到Python安装目录下的Scripts文件夹(比如C:\PythonXX\Scripts或~/.local/bin),将该路径添加到系统环境变量的PATH里,重启终端后再执行pip install dlib。

  • 安装预编译的dlib包
    跳过编译步骤,直接安装第三方预编译的dlib轮子,执行命令:

    pip install dlib-bin
    
  • 安装系统级CMake

    • Windows:下载CMake官方安装包,安装时勾选"Add CMake to the system PATH for all users"选项,完成后重启终端再尝试安装dlib。
    • Linux:使用系统包管理器安装,比如Ubuntu/Debian执行:
      sudo apt-get update && sudo apt-get install cmake
      
      CentOS/RHEL执行:
      sudo yum install cmake
      
    • macOS:通过Homebrew安装:
      brew install cmake
      

内容的提问来源于stack exchange,提问作者Harsh Pathak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 12:42:34