error: subprocess-exited-with-error × Building wheel for dlib (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [45 lines of output] running bdist_wheel running build running build_ext Traceback (most recent call last): File "/root/miniconda3/bin/cmake", line 5, in <module> from cmake import cmake ModuleNotFoundError: No module named 'cmake' ================================================================================ ================================================================================ ================================================================================ CMake is not installed on your system! Or it is possible some broken copy of cmake is installed on your system. It is unfortunately very common for python package managers to include broken copies of cmake. So if the error above this refers to some file path to a cmake file inside a python or anaconda or miniconda path then you should delete that broken copy of cmake from your computer. Instead, please get an official copy of cmake from one of these known good sources of an official cmake: - cmake.org (this is how windows users should get cmake) - apt install cmake (for Ubuntu or Debian based systems) - yum install cmake (for Redhat or CenOS based systems) On a linux machine you can run `which cmake` to see what cmake you are actually using. If it tells you it's some cmake from any kind of python packager delete it and install an official cmake. More generally, cmake is not installed if when you open a terminal window and type cmake --version you get an error. So you can use that as a very basic test to see if you have cmake installed. That is,
时间: 2025-06-05 18:21:19 浏览: 18
### 解决在安装dlib时因缺少官方cmake而导致的subprocess-exited-with-error问题
在安装 `dlib` 时,如果遇到错误提示 `ERROR: CMake must be installed to build dlib` 或者 `subprocess-exited-with-error`,这通常是因为系统中缺少官方版本的 `CMake` 或者其他依赖环境配置不正确[^1]。以下是详细的解决方案:
#### 1. 确保系统已安装官方版 CMake
尽管可以通过 `pip install cmake` 安装一个 Python 包形式的 CMake,但这可能无法满足 `dlib` 的构建需求。因此,建议从官方渠道下载并安装最新版本的 CMake。
- 访问 [CMake 官方网站](https://cmake.org/download/) 下载适用于操作系统的安装程序。
- 安装完成后,确保 CMake 已正确添加到系统的环境变量中。可以通过以下命令验证:
```bash
cmake --version
```
如果返回类似 `cmake version 3.x.x` 的信息,则说明安装成功[^4]。
#### 2. 检查 Visual C++ 环境
`dlib` 的构建依赖于 Visual C++ 编译器。如果未正确安装相关组件,可能会导致构建失败。确保以下步骤已完成:
- 打开 Visual Studio Installer,选择已安装的 Visual Studio 版本。
- 在“工作负载”选项卡中,勾选 **Desktop development with C++** 并安装必要的组件。
- 如果使用的是 Windows 系统,还需确认系统已安装 Microsoft Build Tools[^4]。
#### 3. 升级 pip 和 setuptools
有时,`pip` 或 `setuptools` 的版本过旧也会引发构建问题。建议升级至最新版本:
```bash
pip install --upgrade pip setuptools wheel
```
#### 4. 禁用杀毒软件干扰
某些杀毒软件(例如 360 安全卫士)可能会拦截 `pip` 或 `cmake` 的进程,从而导致构建失败。可以尝试以下方法解决:
- 临时关闭杀毒软件。
- 将 `pip` 和 `cmake` 添加到杀毒软件的信任列表中[^3]。
#### 5. 使用源码安装(成功率更高)
如果通过 `pip install dlib` 仍然报错,可以选择手动编译安装 `dlib`:
1. 克隆 `dlib` 源码仓库:
```bash
git clone https://github.com/davisking/dlib.git
cd dlib
```
2. 构建并安装:
```bash
mkdir build
cd build
cmake ..
cmake --build . --config Release
python setup.py install
```
此方法可以绕过 `pip` 的轮子构建过程,直接使用本地环境完成安装[^1]。
#### 6. 验证安装是否成功
安装完成后,可以通过以下代码验证 `dlib` 是否正常工作:
```python
import dlib
print(dlib.__version__)
```
如果未抛出任何异常,并打印出版本号,则说明安装成功。
---
### 注意事项
- 如果仍遇到问题,建议检查 Python 版本是否与 `dlib` 兼容。推荐使用 Python 3.8 或更高版本。
- 确保系统有足够的磁盘空间和内存以支持编译过程。
---
阅读全文
相关推荐













