# How to fix the "externally-managed-environment" error


Running `pip install` on a system Python protected by [PEP 668](https://pydevtools.com/handbook/explanation/what-is-pep-668.md) produces this error:

```
error: externally-managed-environment

× This environment is externally managed
```

The fix depends on what was being installed.

## Installing project dependencies

Use [uv](https://pydevtools.com/handbook/reference/uv.md) to create a project with its own [virtual environment](https://pydevtools.com/handbook/explanation/what-is-a-virtual-environment.md):

```console
$ uv init my-project
$ cd my-project
$ uv add requests
```

Without uv, create a virtual environment manually:

```console
$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install requests
```

## Installing command-line tools

Tools like `ruff`, `black`, or `httpie` should be installed in isolated environments rather than system-wide. Use `uv tool install` or [pipx](https://pydevtools.com/handbook/reference/pipx.md):

```console
$ uv tool install ruff
$ ruff check .
```

## Overriding the protection

The `--break-system-packages` flag tells pip to ignore the marker:

```console
$ pip install --break-system-packages requests
```

The environment variable `PIP_BREAK_SYSTEM_PACKAGES=1` does the same thing permanently when set in a shell profile.

> [!WARNING]
> Overriding is reasonable inside containers and CI environments where the system Python is disposable. On a desktop or server Linux installation, it risks breaking OS tools that depend on system-managed packages.

## Learn More

- [What is PEP 668?](https://pydevtools.com/handbook/explanation/what-is-pep-668.md)
- [What is a virtual environment?](https://pydevtools.com/handbook/explanation/what-is-a-virtual-environment.md)
- [How to install Python with uv](https://pydevtools.com/handbook/how-to/how-to-install-python-with-uv.md)
- [How to require a virtualenv when installing packages with pip](https://pydevtools.com/handbook/how-to/how-to-require-a-virtual-for-installing-packages.md)
