Ubuntu系统下Python安装dlib库失败问题求助
你执行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_extERROR: 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执行:
CentOS/RHEL执行:sudo apt-get update && sudo apt-get install cmakesudo yum install cmake - macOS:通过Homebrew安装:
brew install cmake
内容的提问来源于stack exchange,提问作者Harsh Pathak

