error: command 'cmake' failed: No such file or directory
ID: pip/cmake-not-found
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 24 | active | — | — | — |
Root Cause
A Python package with C/C++ native extensions requires CMake as a build tool, but CMake is not installed on the system or not found in PATH. This commonly occurs when installing packages like dlib, llama-cpp-python, cmake-build-extension-based packages, or any package that uses CMakeLists.txt for native compilation. The error occurs during pip's build phase when it invokes the package's setup.py or pyproject.toml build system.
genericWorkarounds
-
92% success Install cmake as a system package before running pip install
Install cmake via your system package manager: # Debian/Ubuntu: sudo apt-get update && sudo apt-get install -y cmake build-essential # RHEL/CentOS/Fedora: sudo dnf install -y cmake gcc gcc-c++ make # Alpine (Docker): apk add --no-cache cmake make g++ # macOS: brew install cmake # Then install the Python package: pip install dlib # or whatever package needed cmake # In a Dockerfile: FROM python:3.11-slim RUN apt-get update && apt-get install -y cmake build-essential && rm -rf /var/lib/apt/lists/* RUN pip install dlib
Sources: https://cmake.org/install/ https://pip.pypa.io/en/stable/cli/pip_install/
-
85% success Install cmake via pip first as a separate step, then install the target package
Install cmake from PyPI as a separate step before installing the package that needs it: # Two-step install: pip install cmake pip install llama-cpp-python # Or in a requirements file, split into build-requirements.txt: # build-requirements.txt: cmake>=3.24 setuptools wheel # requirements.txt: dlib>=19.24 # Install sequence: pip install -r build-requirements.txt pip install -r requirements.txt # In CI/CD: - run: pip install cmake setuptools wheel - run: pip install -r requirements.txt
Sources: https://pypi.org/project/cmake/
-
88% success Use a pre-built binary wheel instead of building from source
Many packages that require cmake also publish pre-built wheels for common platforms: # Check if a wheel is available for your platform: pip install --only-binary :all: dlib # For packages with optional binary wheels: pip install llama-cpp-python --prefer-binary # If no wheel exists, check conda-forge which often has pre-built binaries: conda install -c conda-forge dlib # Or use a Docker base image that already includes the built package: FROM nvidia/cuda:12.1-devel-ubuntu22.04 # Many CUDA packages are pre-built in nvidia's images
Sources: https://pip.pypa.io/en/stable/cli/pip_install/#cmdoption-only-binary
Dead Ends
Common approaches that don't work:
-
Installing cmake via pip (pip install cmake) inside the same pip install command
60% fail
When pip is building a package that requires cmake, the build happens in an isolated environment. Even if cmake is installed via pip in the same requirements.txt, pip's dependency resolver may not install cmake first, or the isolated build environment may not have access to the pip-installed cmake binary. The build isolation means the cmake binary needs to be on the system PATH, not just in the virtual environment's bin directory during the build phase.
-
Using --no-build-isolation to make pip find cmake in the virtual environment
55% fail
While --no-build-isolation can work in some cases, it disables pip's build isolation entirely, which means all build dependencies must be pre-installed manually. This creates fragile builds where missing any single build dependency causes cryptic errors. It also means build dependencies can conflict with your project dependencies, leading to version incompatibilities that are hard to diagnose.