How to fix "error: externally-managed-environment" in pip

Tested: we reproduced this error and confirmed the fix on Ubuntu 24.04 with Python 3.12, pip 24.0 and pipx 1.4.3, November 29, 2026.

Your operating system manages this Python, so pip won’t install into it. Create a virtual environment and install there:

python3 -m venv .venv
source .venv/bin/activate
python -m pip install requests

On Ubuntu 24.04’s Python 3.12 the plain pip install requests stopped with this error, and the same install inside .venv worked.

What the error means

An externally managed environment is a Python installation that another package manager looks after, so pip isn’t allowed to change it. Linux distributions (Debian, Ubuntu, Raspberry Pi OS and others) and Homebrew ship a Python that their own package manager relies on. Since PEP 668, they mark it with a file called EXTERNALLY-MANAGED, and pip 23 and later refuse to install packages into it. This is what we got:

error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.

The message lists the three good options. Which one fits depends on what you’re installing. The same check applies to pip uninstall: in our test, uninstalling from the system Python 3.12 stopped with the same error, so remove it with the system package manager instead (sudo apt remove python3-xyz, or brew for Homebrew’s Python).

Pick the right fix

You want to Use Command
Install packages for a project A virtual environment python3 -m venv .venv then python -m pip install ...
Install a command-line tool (black, httpie, yt-dlp) pipx pipx install black
Use a common library system-wide Your OS package sudo apt install python3-requests
Install anything in a throwaway container The override flag pip install --break-system-packages ...

Fix 1: a virtual environment (most cases)

Run these in your project folder. On Debian and Ubuntu, install the venv module first if python3 -m venv says it’s missing:

sudo apt install python3-venv     # Debian and Ubuntu only, if needed
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt

Every new terminal needs source .venv/bin/activate again, or call the environment’s Python directly with .venv/bin/python.

Fix 2: pipx for command-line tools

pipx gives each tool its own hidden environment and puts the command on your PATH:

sudo apt install pipx     # or: brew install pipx
pipx ensurepath
pipx install black

Fix 3: the OS package

For a library your distribution packages, the apt version is safe system-wide. It may be older: on Ubuntu 24.04 apt offered python3-requests 2.31.0, while pip in our venv installed 2.34.2.

What not to do

  • sudo pip install: this writes over files apt owns.
  • pip install --user: still blocked, and it was never a full fix.
  • Deleting the EXTERNALLY-MANAGED file: it comes back with the next Python update and hides the problem rather than solving it.

Confirm it worked

With the environment active, python -c "import sys; print(sys.prefix)" should print your .venv path, and importing the package should work. In our run, import requests reported version 2.34.2 from .venv.

FAQ

Is --break-system-packages safe?

Not on a machine you care about. It lets pip overwrite files your OS package manager installed, and a later system update can break, or be broken by, what pip put there. It's tolerable inside a throwaway container.

What is PEP 668?

The Python standard that lets a distribution mark its Python as managed by the OS. pip sees the EXTERNALLY-MANAGED file next to the standard library and refuses to install outside a virtual environment. PEP 668 has the details.

Does pip install --user avoid it?

No. In our test pip install --user requests gave the same error. Use a virtual environment or pipx.

Why do I see this on a Mac?

Homebrew's Python is marked as externally managed too, so pip3 install against it gives the same error. The same fixes apply.