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

已安装CMake却无法安装dlib库,请求解决编译报错问题

安装dlib时提示找不到'cmake'模块,已重装CMake但问题依旧

我在IDLE中运行代码,尝试安装dlib库时出现报错,错误信息显示构建dlib的wheel未成功执行,提示找不到'cmake'模块,尽管我已重新安装过CMake,但问题仍未解决。错误代码如下:

× Building wheel for dlib (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [11 lines of output]
      running bdist_wheel
      running build
      running build_ext
      Traceback (most recent call last):
        File "<frozen runpy>", line 198, in _run_module_as_main
        File "<frozen runpy>", line 88, in _run_code
        File "C:\Users\Shimb\AppData\Local\Programs\Python\Python311\Scripts\cmake.exe\__main__.py", line 4, in <module>
      ModuleNotFoundError: No module named 'cmake'

      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

解决办法

  • 卸载Python的cmake包,它会和系统级CMake工具产生冲突:
    pip uninstall -y cmake
    
  • 配置系统CMake的环境变量:
    1. 找到CMake的安装目录(默认通常是C:\Program Files\CMake\bin)
    2. 打开系统环境变量设置,将该路径添加到系统PATH列表中
    3. 彻底关闭IDLE和所有命令行窗口,重新启动后再进行安装操作
  • 优先选择预编译的dlib包安装(跳过本地编译步骤):
    pip install dlib-bin
    
  • 若必须源码编译安装:
    先安装Visual Studio 2019/2022的C++桌面开发组件,确认勾选了必要的编译工具,再执行:
    pip install dlib
    

内容的提问来源于stack exchange,提问作者please help im green wario

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 15:42:39