# How to Fix ModuleNotFoundError: No module named 'numpy' During pip Install

This guide helps resolve an issue where a Python package fails to install because it cannot find `numpy`, even though it is already installed in your [virtual environment](https://pydevtools.com/handbook/explanation/what-is-a-virtual-environment.md).

## Problem

You're trying to install a Python package using:

```bash
uv pip install git+https://github.com/example/examplepkg.git
# or
pip install .
```

Even though `numpy` is installed in your [environment](https://pydevtools.com/handbook/explanation/what-is-a-virtual-environment.md), the install fails with:

```text
ModuleNotFoundError: No module named 'numpy'
```

## Why This Happens

By default, [pip](https://pydevtools.com/handbook/reference/pip.md) (and [uv](https://pydevtools.com/handbook/reference/uv.md) pip) use **build isolation** when installing packages that declare a build backend in [pyproject.toml](https://pydevtools.com/handbook/reference/pyproject.toml.md). This means they build the package in a temporary, isolated environment with *only* the dependencies listed in the `[build-system]` table of `pyproject.toml`.

If `numpy` is required during the build (e.g. to compile C extensions) but not listed in `build-system.requires`, it will not be available, leading to the error.

## Solution

Use the `--no-build-isolation` flag to bypass the isolated environment and allow access to already-installed packages:

```bash
pip install --no-build-isolation .
# or
uv pip install --no-build-isolation git+https://github.com/example/examplepkg.git
```

{{< callout type="info" >}}
  This works because `--no-build-isolation` tells pip to use your current environment, where `numpy` is already installed. This avoids the problem entirely, but at the cost of potentially inconsistent builds.
{{< /callout >}}

## Permanent Fix: Add Build Requirements

A better long-term solution is to ensure that required build dependencies like `numpy` are declared in `pyproject.toml`, following [PEP 518](https://pydevtools.com/handbook/explanation/what-is-pep-517.md):

```toml
[build-system]
requires = ["setuptools", "wheel", "numpy"]
build-backend = "setuptools.build_meta"
```

This allows pip to correctly build the package in an isolated environment with the necessary dependencies.

{{< callout type="warning" >}}
  Missing build requirements are a common source of install failures. Always specify required build-time packages explicitly in `[build-system.requires]` to ensure compatibility with modern Python packaging tools.
{{< /callout >}}

## See Also

* [PEP 517: A build-system independent format for source trees](https://peps.python.org/pep-0517/)
* [PEP 518: Specifying Minimum Build System Requirements](https://peps.python.org/pep-0518/)
* [What is PEP 517/518 compatibility](https://pydevtools.com/handbook/explanation/what-is-pep-517.md)
* [What is a Build Backend?](https://pydevtools.com/handbook/explanation/what-is-a-build-backend.md)
* [pyproject.toml reference page](https://pydevtools.com/handbook/reference/pyproject.toml.md)
