pip: error: externally-managed-environment
Most likely cause: Running pip install against the system Python on a distro that ships an EXTERNALLY-MANAGED marker (PEP 668)
Try first: Create a virtual environment (recommended) (python3 -m venv .venv && . .venv/bin/activate && pip install requests)
Likely causes
- Running pip install against the system Python on a distro that ships an EXTERNALLY-MANAGED marker (PEP 668)most likely
- Homebrew's Python on macOS, which also marks itself externally managedpossible
- A script or Dockerfile written before the change that installs globally with pipless likely
Why this happens
Linux distributions use Python for their own tools, such as apt helpers and system scripts. When pip installs or upgrades a package globally, it can replace a version those tools depend on and break the system. PEP 668 lets a distro put an EXTERNALLY-MANAGED file next to its Python's standard library; pip 23+ sees it and refuses global installs with this error. Nothing is broken; pip is protecting the system install.
Which option to use
- Writing code or running a project: virtual environment.
- Installing a command-line tool: pipx.
- A library your distro already packages: apt/dnf/pacman.
- Never
sudo pip installon these systems.
How to fix it
Create a virtual environment (recommended)Safe
In your project folder, create and activate a venv, then pip works normally inside it. On Debian/Ubuntu you may need
sudo apt install python3-venvfirst.python3 -m venv .venv && . .venv/bin/activate && pip install requestsUse pipx for command-line toolsChanges settings
For apps like black, httpie or yt-dlp, pipx gives each its own environment and puts the command on your PATH.
sudo apt install pipx && pipx ensurepath && pipx install blackUse the system package if one existsChanges settings
Many libraries are packaged by the distro, e.g.
sudo apt install python3-requests. These are tested with the system Python.sudo apt install python3-requestsIn Docker, use a venv or the official python imageChanges settings
The official
python:3.ximages are not externally managed. On distro images, create a venv in the Dockerfile and put it first on PATH.Install for your user only (last resort)Dangerous
pip install --user --break-system-packages <pkg>installs into ~/.local. It can still conflict with system packages, so prefer a venv.pip install --user --break-system-packages requests⚠ This can break distro tools that rely on specific package versions. Back up or snapshot important systems first, and prefer a virtual environment.
If that didn't fix it
If pip still errors inside an activated venv, check `which pip` points into .venv; if not, run `python -m pip install ...` instead.
When to see a technician
No technician needed. On a managed server, ask the administrator which Python environment you should use.
Questions people ask
- Can I just delete the EXTERNALLY-MANAGED file?
- You can, but it removes the protection for everything on the system and comes back with the next Python package update. A virtual environment is safer and just as quick.
- Does this affect Windows?
- No. The python.org Windows installer is not externally managed. You will see this on Linux distributions and Homebrew Python.
Sources
- PEP 668: Marking Python base environments as externally managed
- Python Packaging User Guide: Externally managed environments