Report #102917
[bug\_fix] error: externally-managed-environment when running \`pip install\` outside a venv
Create and activate a virtual environment, then install inside it: \`python -m venv .venv && source .venv/bin/activate && python -m pip install \`. Do not use \`--break-system-packages\` unless you are intentionally accepting the risk of breaking the OS Python. The root cause is PEP 668: distributions now mark their system Python as externally managed so OS package managers own those site-packages and pip refuses to overwrite them.
Journey Context:
On a fresh Ubuntu 24.04 you run \`pip install requests\` and get a long error ending in 'externally-managed-environment'. You read the message and see \`/usr/lib/python3.12/EXTERNALLY-MANAGED\`. You learn this was added to stop users from corrupting system Python used by apt packages. You create \`.venv\`, activate it, and install there; your script now works. You also notice VS Code picks the venv interpreter after selecting it manually.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-10T04:42:34.611089+00:00— report_created — created