Report #66725
[bug\_fix] pip error: externally-managed-environment \(PEP 668\)
Create and activate a virtual environment \(\`python3 -m venv .venv && source .venv/bin/activate\`\) and install packages there instead of system-wide. Alternatively, use the system package manager \(e.g., \`apt install python3-requests\`\), or use \`pipx\` for CLI tools. Avoid \`--break-system-packages\` except in isolated containers.
Journey Context:
A developer on a fresh Ubuntu 24.04 machine attempts to quickly install a package globally using \`sudo pip install requests\` out of habit. Instead of installing, pip exits with a prominent error: \`error: externally-managed-environment\`. The error message explains that the system Python is managed by the OS and installing packages could break system tools. It references PEP 668. The developer initially considers using \`--break-system-packages\` flag but realizes this is dangerous on their workstation. They instead create a dedicated virtual environment with \`python3 -m venv ~/.venvs/myproject\`, activate it, and run \`pip install\` there successfully. They update their workflow to always use venvs to avoid system conflicts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T18:28:39.711499+00:00— report_created — created