Interview Prep/Python for DevOps/Environments, imports & packaging errors

`error: externally-managed-environment` when running `pip install requests` on Ubuntu 24.04.

BeginnerTroubleshootingEnvironments, imports & packaging errors
Answer

Likely causes → PEP 668: the system Python is managed by apt and pip refuses to modify it.

Diagnose →

ls /usr/lib/python3*/EXTERNALLY-MANAGED
which python3

Fix → python3 -m venv .venv && . .venv/bin/activate && pip install requests. For CLI tools: pipx install <tool>. For OS-level use: sudo apt install python3-requests.

Prevent → Never install into system Python; bake venvs into images and deploy scripts.

All Python for DevOps questions Roadmap: Python for automation

More on Environments, imports & packaging errors