error: externally-managed-environment means pip found a marker file telling it that your Python's base environment belongs to the OS package manager (apt, Homebrew, apk, pacman), so it refuses to install there. The fix is to stop installing into that interpreter: use a virtual environment (python3 -m venv .venv or uv venv) for project libraries, and pipx install or uv tool install for command-line apps. Passing --break-system-packages silences the error, but it is only reasonable inside a throwaway container, never on a workstation or server you care about.
The rest of this guide explains where the error comes from, which systems produce it, the fix for each situation, and the Dockerfile patterns that avoid it without disabling the guard. Every command below was run on macOS with Homebrew Python 3.14.6, pip 26.1.2, uv 0.13.12 and pipx 1.19.2 in December 2026, and the error output is copied from a real terminal.
What the externally-managed-environment error actually means
The error is defined by PEP 668, now maintained as the PyPA Externally Managed Environments specification. The mechanism is simple: a distributor drops a file called EXTERNALLY-MANAGED into the interpreter's standard library directory (the path returned by sysconfig.get_path("stdlib", sysconfig.get_default_scheme())). When an installer such as pip or uv is about to write into an interpreter that is not a virtual environment and that file exists, it must stop and print the message inside the file.
Here is the real output from Homebrew's Python on a Mac:
$ python3.14 -m pip install requests
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
xyz, where xyz is the package you are trying to
install.
If you wish to install a Python library that isn't in Homebrew,
use a virtual environment:
python3 -m venv path/to/venv
source path/to/venv/bin/activate
python3 -m pip install xyz
...
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
The body of that message is not pip's text. It is the Error key of the marker file, which is a plain INI file you can read yourself:
python3 -c "import sysconfig; print(sysconfig.get_path('stdlib', sysconfig.get_default_scheme()))"
# /opt/homebrew/opt/python@3.14/Frameworks/Python.framework/Versions/3.14/lib/python3.14
cat "$(python3 -c "import sysconfig; print(sysconfig.get_path('stdlib', sysconfig.get_default_scheme()))")/EXTERNALLY-MANAGED"
[externally-managed]
Error=To install Python packages system-wide, try brew install
xyz, where xyz is the package you are trying to
install.
...
Why distributions turned it on
The problem PEP 668 solves is two package managers fighting over one directory. On Debian, apt installs Python libraries that system tools depend on. If you sudo pip install a newer version of one of those libraries, pip happily overwrites or shadows it, and the next time an OS tool imports it you get a broken package manager, a broken desktop applet or a failed upgrade. pip has no idea which files apt owns, and apt has no idea what pip changed. The marker file is the distributor's way of saying "this interpreter is ours; bring your own environment."
The check is deliberately narrow. The spec says the rule applies only when sys.prefix == sys.base_prefix, which is how installers detect that they are not inside a virtual environment. That is why every real fix below boils down to "create a separate environment," and why the error never appears inside an activated venv.
Which systems show the error
| Platform | Marker present? | Notes |
|---|---|---|
| Debian 12 (bookworm) and later | Yes | The Debian 12 release notes state the python3.11 and pypy3 interpreters are marked externally-managed and recommend pipx and venv. Debian 13 carries it forward. |
| Ubuntu 24.04 LTS and 26.04 LTS | Yes | Ubuntu inherits Debian's Python packaging. Ubuntu 26.04 moved from Python 3.12 to 3.14, so after an upgrade your old --break-system-packages installs live under a Python version that is no longer the default. |
| Homebrew Python (macOS and Linux) | Yes | The Homebrew docs say: "Homebrew marks its current Python as externally managed according to PEP 668." |
| Arch Linux | Yes | Implemented in the python package at 3.11.3-2 (Arch bug FS#78413, closed June 2023). |
| Alpine Linux | Yes | The python3 package ships the marker, which is why bare pip install fails in alpine images (aports issue #14617). |
| Fedora / RHEL family | No | A Fedora change proposal existed, but a Fedora Python maintainer wrote in November 2023 that "This change was never submitted." Fedora instead patches pip so sudo pip install goes to /usr/local. |
Official python: Docker images |
No | They compile CPython from source into /usr/local on top of Debian (see the docker-library Dockerfile), so there is no distro-owned interpreter to protect. |
| pyenv, uv-managed, python.org installers, conda | No | You own these interpreters; nothing else depends on them. |
A quick way to see whether the machine you are on is protected:
python3 -c "import sysconfig, pathlib; p = pathlib.Path(sysconfig.get_path('stdlib', sysconfig.get_default_scheme())) / 'EXTERNALLY-MANAGED'; print(p, p.exists())"
If you hit the error on a Mac and are surprised, check which python3. Once /opt/homebrew/bin comes before pyenv shims or the python.org framework on your PATH, you are talking to Homebrew's interpreter, and you get Homebrew's rules.
Fix 1: use a virtual environment for project dependencies
For anything that is a project (a web app, a notebook, a script with dependencies), create a venv in the project directory. This is the fix the marker file itself recommends, and it is the one you should reach for 90% of the time.
cd my-project
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
python -m pip install requests # no error: sys.prefix != sys.base_prefix
python -c "import sys; print(sys.prefix, sys.base_prefix)"
On Debian and Ubuntu, python3 -m venv fails until you install the venv module, because Debian splits ensurepip out of the base package. Install it with apt; on 26.04 the versioned package matches the 3.14 interpreter:
sudo apt install python3-venv # or python3.14-venv for the specific version
Two habits that prevent the error from coming back:
- Use
python -m piprather than a barepip. On a machine with several interpreters,pipon yourPATHmay belong to a different Python thanpythondoes. Homebrew's docs make the same recommendation. - Do not run
pip install --upgrade pipagainst the base interpreter to "fix" things. Homebrew explicitly says not to do this; upgrade pip inside the venv instead.
If you need one or two OS-packaged libraries that are painful to build (GObject bindings, for example), python3 -m venv --system-site-packages .venv lets the venv see the distro's packages while still installing your own into the venv. Use it sparingly; it reintroduces some coupling to OS upgrades.
The faster equivalent: uv venv
If you already use uv, it does the same thing faster and can also download a standalone interpreter so you never touch the distro's Python at all:
uv venv # creates .venv with the default interpreter
uv pip install requests # installs into .venv without activation
# or for a managed project:
uv init && uv add requests # writes pyproject.toml + uv.lock and syncs .venv
uv honours the marker too. When I pointed it at Homebrew's interpreter with --system, it refused with the same message:
$ uv pip install --system --python /opt/homebrew/bin/python3.14 six
Using Python 3.14.6 environment at: /opt/homebrew/opt/python@3.14/Frameworks/Python.framework/Versions/3.14
error: The interpreter at `/opt/homebrew/opt/python@3.14/Frameworks/Python.framework/Versions/3.14` is externally managed, and indicates the following:
To install Python packages system-wide, try brew install
...
If you are choosing between uv, conda and pixi for environment management more broadly, our uv vs Conda vs Pixi comparison covers the trade-offs.
Fix 2: use pipx or uv tool for command-line applications
The other common trigger is installing a tool rather than a library: pip install httpie, pip install yt-dlp, pip install ansible. You want the command on your PATH, not the package importable in your interpreter. That is exactly what pipx and uv tool do: each application gets its own hidden venv, and its entry points are linked into ~/.local/bin.
# pipx (Debian/Ubuntu: sudo apt install pipx; macOS: brew install pipx)
pipx install httpie
pipx ensurepath # adds ~/.local/bin to PATH in your shell profile
pipx inject httpie httpie-jwt-auth # add a plugin into that app's venv
pipx upgrade-all
# uv equivalent
uv tool install httpie
uv tool update-shell # same idea as ensurepath
uv tool upgrade --all
uvx ruff check . # run a tool once without installing it
Both worked against the externally managed Homebrew interpreter in my test without any override, because neither installs into the base environment. uv tool install httpie printed Installed 3 executables: http, httpie, https, and pipx install --python /opt/homebrew/bin/python3.14 pycowsay succeeded the same way.
Before reaching for either, check whether the distro already packages the tool. sudo apt install python3-requests or brew install yt-dlp is a perfectly good answer when you just need a common library for a system script and are happy with the distro's version.
When --break-system-packages is acceptable (and when it is not)
pip's own reference describes the flag as "Allow pip to modify an EXTERNALLY-MANAGED Python installation" and lists the environment variable PIP_BREAK_SYSTEM_PACKAGES as its equivalent (pip install docs, v26.3). uv has the same switch as --break-system-packages / UV_BREAK_SYSTEM_PACKAGES (uv environment variables). All of these work; the question is where.
Acceptable: a container image that runs one application, is rebuilt from scratch on every change, and in which nothing else uses the system Python. In that case there is no apt-installed tool to break at runtime, and if a build breaks you find out in CI. Even then, I prefer a venv in the image (see the next section) because it costs one line.
Not acceptable: your laptop, a long-lived VM, a CI runner image you maintain, or any server that receives apt upgrade. On Debian-family hosts, sudo pip install --break-system-packages writes into /usr/local/lib/python3.X/dist-packages, which comes ahead of apt's /usr/lib/python3/dist-packages on sys.path. Anything you install there silently shadows the version OS tools were tested against. The breakage shows up weeks later, typically during a release upgrade, and is miserable to trace.
The worst variant is making it permanent. Homebrew's own marker message mentions that adding break-system-packages = true to pip.conf "will permanently disable this error." Setting PIP_BREAK_SYSTEM_PACKAGES=1 in your shell profile does the same. Do not do either on a host; you are deleting the guard rail for every future install, including the ones you forget about.
Two other workarounds you will see recommended online, and why I avoid them:
pip install --userdoes not bypass the check. With the marker present, pip refuses--userinstalls as well; I confirmedpython3.14 -m pip install --user requestsfails with the same error on Homebrew. With the override, user-site packages still shadow system ones for every script you run.- Deleting the
EXTERNALLY-MANAGEDfile works until the next package update restores it, and it removes protection for everyone on the machine. In a disposable container it is equivalent to the env var; on a host it is worse.
One subtle gotcha: pip install --target DIR is not blocked. The spec only covers installs into a sysconfig scheme, and in my test pip install --target ./tgt six succeeded on Homebrew Python. That is legitimate for vendoring into a Lambda zip or a plugin directory, but it is not a way to "install globally."
Dockerfile patterns that avoid the error
Most people hit this error for the first time when a Dockerfile that has worked for years starts failing after a base image bump from ubuntu:22.04 to ubuntu:24.04, or from debian:bullseye to bookworm. You have three clean options.
Pattern A: use the official python image
The official python:3.x images build CPython into /usr/local and do not ship the marker, so pip install works without flags. This is the least surprising choice for Python services.
FROM python:3.14-slim-trixie
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "-m", "myapp"]
Pattern B: distro image plus a venv
When you need a distro base (for system libraries, or because your organisation mandates one), create a venv and put it first on PATH. Every later pip and python call uses the venv, so you never touch the system interpreter:
FROM ubuntu:26.04
RUN apt-get update \
&& apt-get install -y --no-install-recommends python3 python3-venv \
&& rm -rf /var/lib/apt/lists/*
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv "$VIRTUAL_ENV"
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "-m", "myapp"]
This also makes multi-stage builds easy: build the venv in a builder stage with compilers installed, then COPY --from=builder /opt/venv /opt/venv into a slim runtime stage.
Pattern C: uv in the image
The uv Docker guide recommends copying the static binary from its image (pin the version) and syncing from the lockfile with a cache mount:
FROM python:3.14-slim-trixie
COPY --from=ghcr.io/astral-sh/uv:0.13.12 /uv /uvx /bin/
ENV UV_LINK_MODE=copy \
UV_COMPILE_BYTECODE=1 \
UV_NO_DEV=1
WORKDIR /app
COPY . /app
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked
ENV PATH="/app/.venv/bin:$PATH"
CMD ["python", "-m", "myapp"]
If you really must install into the system Python in a container
Scope the override to the one command rather than setting it globally, so a future RUN in a derived image does not inherit it by accident:
FROM debian:trixie-slim
RUN apt-get update && apt-get install -y --no-install-recommends python3 python3-pip \
&& rm -rf /var/lib/apt/lists/*
RUN pip install --no-cache-dir --break-system-packages awscli-local
uv pip install --system plus --break-system-packages behaves the same way; uv's Docker guide also documents UV_SYSTEM_PYTHON=1 for images whose interpreter is not marked, such as the official python images.
A decision checklist
| Situation | Do this |
|---|---|
| Installing a library for a project | python3 -m venv .venv or uv venv / uv add |
| Installing a CLI tool (httpie, ansible, yt-dlp) | pipx install or uv tool install |
| Running a tool once | uvx tool or pipx run tool |
| Common library for a small system script | apt install python3-<name> / brew install <name> |
| Python service in Docker | Official python: image, or venv on PATH |
| Throwaway single-app container on a distro base | --break-system-packages on that one RUN is tolerable |
| Laptop, server, CI runner image | Never disable the marker |
If this error appeared because you just moved to a new Python minor version, it is a good moment to rebuild venvs cleanly rather than copying site-packages around; our Python 3.15 upgrade guide covers what to check when you do. If it showed up right after a release upgrade, see the Python notes in our Ubuntu 24.04 to 26.04 upgrade guide.
Frequently Asked Questions
Is it safe to use --break-system-packages?
It is safe enough inside a disposable, single-purpose container that you rebuild on every change. On a workstation or server it is not: packages you install shadow the versions the OS's own Python tools were tested with, and the breakage usually appears later, during an upgrade. Use a venv, pipx or uv tool instead.
Why does pip install --user also fail with externally-managed-environment?
Because user-site installs still change what the system interpreter imports, the marker blocks them too. Only installs into a virtual environment (where sys.prefix differs from sys.base_prefix) are exempt. I confirmed pip install --user fails on Homebrew Python with the marker present.
How do I fix externally-managed-environment on macOS?
You are almost certainly using Homebrew's Python. Create a venv per project (python3 -m venv .venv), install apps with brew install pipx then pipx install <app>, or use uv. If you prefer an interpreter you fully control, install one with uv or pyenv and put it first on your PATH.
Does Fedora have the externally-managed-environment error?
No. Fedora never shipped the EXTERNALLY-MANAGED marker; a Fedora Python maintainer said in 2023 that the change was never submitted. Fedora patches pip so sudo pip install lands in /usr/local instead of /usr. You should still prefer a venv there, for the same reasons.
Can I just delete the EXTERNALLY-MANAGED file?
You can, and pip will stop complaining, but a later package update usually restores the file and you have removed the protection for every user and script on the machine. In a throwaway container it is equivalent to PIP_BREAK_SYSTEM_PACKAGES=1; on a host it is a bad idea.
Why did my Dockerfile start failing after upgrading the base image?
Older bases such as ubuntu:22.04 and debian:bullseye did not mark their Python as externally managed, while ubuntu:24.04, debian:bookworm and newer do. Switch to an official python: image, add a venv to the Dockerfile, or use uv with a project venv.
Bottom Line
externally-managed-environment is the OS telling you not to mix pip into a Python it depends on. Treat it as a pointer, not an obstacle: one venv per project, pipx or uv tool for CLI apps, official python: images or a venv in containers, and --break-system-packages only on a single RUN line in an image you are about to throw away. Set things up that way once and the error stops appearing, along with the much harder-to-debug breakage it was designed to prevent.