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

已安装Cmake仍无法安装dlib:虚拟环境中Cmake未被识别

问题:安装dlib时提示CMake未找到(已通过pip安装CMake)

已通过pip install cmake安装了CMake(版本3.29.0.1),同时安装了wheel和numpy,但执行pip install dlib时反复报错ERROR: CMake must be installed to build dlib。虚拟环境目录中存在CMake文件,且pip list明确显示CMake已安装,尝试过官网安装CMake、卸载重装pip版CMake均无效。

环境信息:

  • 编辑器:VSCode
  • Python版本:3.12.2

报错详细输出

PS G:\WORK\EncroFace> pip install dlib --verbose
Using pip 24.0 from G:\WORK\EncroFace\venv\Lib\site-packages\pip (python 3.12)
Collecting dlib
  Using cached dlib-19.24.4.tar.gz (3.3 MB)
  Running command pip subprocess to install build dependencies
  Collecting setuptools
    Using cached setuptools-69.2.0-py3-none-any.whl.metadata (6.3 kB)
  Collecting wheel
    Using cached wheel-0.43.0-py3-none-any.whl.metadata (2.2 kB)
  Using cached setuptools-69.2.0-py3-none-any.whl (821 kB)
  Using cached wheel-0.43.0-py3-none-any.whl (65 kB)
  Installing collected packages: wheel, setuptools
  Successfully installed setuptools-69.2.0 wheel-0.43.0
  Installing build dependencies ... done
  Running command Getting requirements to build wheel
  <string>:210: SyntaxWarning: invalid escape sequence '\('
  <string>:211: SyntaxWarning: invalid escape sequence '\('
  <string>:212: SyntaxWarning: invalid escape sequence '\('
  running egg_info
  writing tools/python\dlib.egg-info\PKG-INFO
  writing dependency_links to tools/python\dlib.egg-info\dependency_links.txt
  writing top-level names to tools/python\dlib.egg-info\top_level.txt
  reading manifest file 'tools/python\dlib.egg-info\SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  no previously-included directories found matching 'tools\python\build*'
  no previously-included directories found matching 'dlib\cmake_utils\*\build*'
  no previously-included directories found matching 'dlib\test'
  warning: no previously-included files matching '*.pyc' found anywhere in distribution
  adding license file 'LICENSE.txt'
  writing manifest file 'tools/python\dlib.egg-info\SOURCES.txt'
  Getting requirements to build wheel ... done
  Running command Preparing metadata (pyproject.toml)
  <string>:210: SyntaxWarning: invalid escape sequence '\('
  <string>:211: SyntaxWarning: invalid escape sequence '\('
  <string>:212: SyntaxWarning: invalid escape sequence '\('
  running dist_info
  creating C:\Users\benjamin\AppData\Local\Temp\pip-modern-metadata-oiqzlulr\dlib.egg-info
  writing C:\Users\benjamin\AppData\Local\Temp\pip-modern-metadata-oiqzlulr\dlib.egg-info\PKG-INFO
  writing dependency_links to C:\Users\benjamin\AppData\Local\Temp\pip-modern-metadata-oiqzlulr\dlib.egg-info\dependency_links.txt
  writing top-level names to C:\Users\benjamin\AppData\Local\Temp\pip-modern-metadata-oiqzlulr\dlib.egg-info\top_level.txt
  writing manifest file 'C:\Users\benjamin\AppData\Local\Temp\pip-modern-metadata-oiqzlulr\dlib.egg-info\SOURCES.txt'
  reading manifest file 'C:\Users\benjamin\AppData\Local\Temp\pip-modern-metadata-oiqzlulr\dlib.egg-info\SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  no previously-included directories found matching 'tools\python\build*'
  no previously-included directories found matching 'dlib\cmake_utils\*\build*'
  no previously-included directories found matching 'dlib\test'
  warning: no previously-included files matching '*.pyc' found anywhere in distribution
  adding license file 'LICENSE.txt'
  writing manifest file 'C:\Users\benjamin\AppData\Local\Temp\pip-modern-metadata-oiqzlulr\dlib.egg-info\SOURCES.txt'
  creating 'C:\Users\benjamin\AppData\Local\Temp\pip-modern-metadata-oiqzlulr\dlib-19.24.4.dist-info'
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: dlib
  Running command Building wheel for dlib (pyproject.toml)
  <string>:210: SyntaxWarning: invalid escape sequence '\('
  <string>:211: SyntaxWarning: invalid escape sequence '\('
  <string>:212: SyntaxWarning: invalid escape sequence '\('
  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 "G:\WORK\EncroFace\venv\Scripts\cmake.exe\__main__.py", line 4, in <module>
  ModuleNotFoundError: No module named 'cmake'

  ERROR: CMake must be installed to build dlib

  error: subprocess-exited-with-error

  × Building wheel for dlib (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: 'G:\WORK\EncroFace\venv\Scripts\python.exe' 'G:\WORK\EncroFace\venv\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py' build_wheel 'C:\Users\benjamin\AppData\Local\Temp\tmpjicuj8sb'
  cwd: C:\Users\benjamin\AppData\Local\Temp\pip-install-8curvry1\dlib_b75c506e5565413494e9496a676891ed
  Building wheel for dlib (pyproject.toml) ... error
  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
PS G:\WORK\EncroFace>

pip list输出(显示CMake已安装)

PS G:\WORK\EncroFace> pip list
Package         Version
--------------- --------
build           1.2.1   
cmake           3.29.0.1
colorama        0.4.6   
numpy           1.26.4  
packaging       24.0    
pip             24.0    
pyproject_hooks 1.0.0   
setuptools      69.2.0  
wheel           0.43.0  
PS G:\WORK\EncroFace> 

解决方案

1. 改用官方CMake二进制版(推荐)

pip安装的CMake是Python封装版,可能在编译dlib时出现路径或调用问题,改用官方原生版本更可靠:

  • 卸载pip版CMake:pip uninstall -y cmake
  • 下载官方Windows安装包,安装时务必勾选**"Add CMake to the system PATH for all users"**(或当前用户)
  • 重启VSCode和终端,输入cmake --version验证,能正常显示版本号即可
  • 重新激活虚拟环境,执行pip install dlib

2. 修复pip版CMake的损坏问题

如果坚持使用pip版CMake,可尝试以下步骤:

  • 直接在终端运行虚拟环境中的CMake:.\venv\Scripts\cmake.exe --version,若仍报ModuleNotFoundError,说明安装已损坏
  • 删除现有虚拟环境,重新创建并安装依赖:
    Remove-Item -Recurse venv
    python -m venv venv
    .\venv\Scripts\activate
    pip install wheel numpy
    pip install dlib
    

3. 安装预编译的dlib包

跳过编译过程,直接安装预编译好的wheel包:

pip install dlib-bin

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 15:34:52