externally-managed-environment 🐍 Python

error: externally-managed-environment

Your system Python (Debian 12+, Ubuntu 23.04+, Homebrew) refuses pip installs into the OS-managed environment (PEP 668).

Seen on: Python

Meaning

Installing packages globally can break OS tools that depend on system Python. pip now blocks it and suggests a virtual environment.

Common causes

  • pip install outside a virtual environment on a PEP 668 system
  • Using sudo pip

⚡ Quick fix

  1. Create a venv: python3 -m venv .venv && . .venv/bin/activate
  2. Use pipx for CLI tools
  3. Install the apt package (python3-xyz) for system-wide libraries

Detailed fix by platform

Linux

  1. python3 -m venv .venv && . .venv/bin/activate && pip install -r requirements.txt

How to diagnose

  1. Environment — Inside a venv?
  2. Tool — Is it a CLI app (use pipx)?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.