Report #59546
[bug\_fix] error: externally-managed-environment when using pip install outside a venv on Debian 12/Ubuntu 23.04\+
Create and activate a virtual environment \(\`python3 -m venv venv && source venv/bin/activate\`\) and run pip inside it, or use \`pip install --break-system-packages\` as a last resort \(strongly discouraged for production systems\). The root cause is PEP 668, adopted by modern Linux distributions, which marks the system Python as externally managed to prevent package managers \(pip\) from breaking system tools that depend on specific Python package versions installed via the OS package manager \(apt/dnf\).
Journey Context:
You spin up a new Ubuntu 23.10 VM and try to \`sudo pip install requests\` to quickly get a script working. Instead of installing, pip errors out with \`error: externally-managed-environment\` and suggests using \`apt install python3-requests\`. You try \`pip install --user requests\` but your script still can't find it because of PATH issues. You check \`/usr/lib/python3.11/EXTERNALLY-MANAGED\` and see the marker file indicating PEP 668 compliance. You realize that the system Python is reserved for system packages managed by apt to avoid conflicts with OS utilities that depend on specific Python package versions. You create a virtual environment with \`python3 -m venv venv\`, activate it, and run \`pip install requests\` inside the venv. The install succeeds because the venv's pip is not restricted by the EXTERNALLY-MANAGED marker, and your script runs correctly using the isolated venv interpreter.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T06:26:20.802437+00:00— report_created — created