Fix pip "error: externally-managed-environment" on Ubuntu 24.04 / Debian 12
The problem
On a fresh Ubuntu 24.04 box, pip install requests refused:
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-requests ...
PEP 668 marks the system interpreter as apt-owned, so pip declines to touch it.
What didn't work
pip install --break-system-packages requests— works once, then the next apt upgrade fights your pip-installed versions and system tooling breaks subtly.sudo pip install requests— can overwrite files under/usr/lib/python3/dist-packagesthat apt owns, which is the exact failure the marker exists to prevent.- Deleting
/usr/lib/python3.12/EXTERNALLY-MANAGED— "fixes" it until the next python3 update restores the file, and now nothing warns you.
The fix
# fast path (2026): uv — venv + installs ~10x faster than pip
curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv .venv && source .venv/bin/activate
uv pip install requests # or: uv add requests (writes pyproject + lockfile)
# stdlib fallback, no extra tooling:
python3 -m venv .venv
source .venv/bin/activate
pip install requests
The marker only governs the system site-packages; a virtualenv has its own, so pip is unrestricted there while apt keeps owning the system packages.
Why it works
externally-managed-environment protects the interpreter's system site-packages from pip; a venv (or uv-managed project) isolates installs into a private site-packages, which satisfies the PEP 668 guarantee while giving every project its own dependency set.