Report #40983
[bug\_fix] error: externally-managed-environment × This environment is externally managed
Create and activate a virtual environment \('python3 -m venv ~/.venv/myproject && source ~/.venv/myproject/bin/activate'\) then use pip inside it, or use 'pipx' for applications, or use '--break-system-packages' flag \(strongly discouraged for system stability\).
Journey Context:
Developer on Ubuntu 23.04 runs 'sudo pip install flask' to install Flask system-wide for a quick test. Instead of installing, pip throws an error: 'externally-managed-environment'. The error message explains that the system Python is managed by the OS package manager \(apt\) and pip installing packages could break system tools. Developer learns about PEP 668 which adds a marker file /usr/lib/python3.11/EXTERNALLY-MANAGED. The correct approach is to never install to system Python. Developer creates a virtual environment with 'python3 -m venv myenv', activates it, and pip works normally there. Alternatively, for CLI tools, they learn to use 'pipx install flake8' which manages the venv automatically.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T23:15:45.732905+00:00— report_created — created