pip "externally-managed-environment" (Ubuntu 23.04+): The Right Fix

Symptom

pip install fails with "error: externally-managed-environment".

Root cause

PEP 668: newer distros forbid pip from trampling the system Python.

Fix, in order

1. Use a virtualenv — the intended pathpython3 -m venv .venv && source .venv/bin/activate && pip install <pkg>
2. For CLI tools, use pipxpipx install <tool>
3. Never reflex --break-system-packages on servers# it works, then breaks apt-managed packages

Prevent it coming back

One venv per project; system Python stays pristine.

Run it on clean infra

Spinning up a fresh box to reproduce or escape this error?

Managed cloud hosting

Related

Cloud & DevOps tool comparisons · Hardware build guides

NinjaOps publishes free engineering guides. Some outbound links are affiliate links: they cost you nothing and support the site.

Last reviewed 2026-10-02 · NinjaOps SEO grid · DevOps blog