About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.
When pip install stops with error: externally-managed-environment and × This environment is externally managed, the Python you are using belongs to the operating system's package manager. pip found a marker file named EXTERNALLY-MANAGED and you are not inside a virtual environment, so it refuses to touch the system's packages. Create a virtual environment for a project, or use pipx for a command-line application. The override flag exists but can break the system.
What the error means
PEP 668 sets the rule. Before a Python installer such as pip installs into a Python, it checks two things: whether it is running outside a virtual environment, and whether an EXTERNALLY-MANAGED file exists in the directory returned by sysconfig.get_path("stdlib", sysconfig.get_default_scheme()). If both are true the installer "should exit with an error message". The PEP says the installer should offer an override such as --break-system-packages, and that it "should not be enabled by default".
pip 24.3.1 builds the first line of its message from the word error and the reference externally-managed-environment, in exceptions.py; no documentation page prints the line. It implements the PEP in check_externally_managed(): it returns at once when running under a virtual environment, looks for the marker in the standard library directory, and raises the error when the file exists. The error object in exceptions.py has the reference externally-managed-environment, the message "This environment is externally managed", and a 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." Its hint reads "See PEP 668 for the detailed specification."
The explanatory text between the message and the note is not pip's. pip reads it from the Error key of the marker file, so your distribution writes it. If the file has none, pip prints its own default, which begins "The Python environment under" followed by the prefix path and says the environment "is managed externally".
The reason is in the PEP's rationale. A package installed with pip into the system Python is visible to the operating system's own Python software, and a newer, incompatible version "may break software shipped by the distro". The PEP's example is that a pip install can break Fedora's dnf command. It adds that sudo pip uninstall can remove packages the system's package manager shipped. This applies to user installs too: the PEP says it covers "pip install --user" because those packages also appear on the system interpreter's path.
pipx's install page lists the distributions that adopt it as Ubuntu 23.04+, Debian 12+ and Fedora 38+.
Likely causes
| Cause | What you see | How to confirm |
|---|---|---|
pip install run against the system Python with no virtual environment |
The error above | which python does not point into a .venv folder |
Run with sudo |
Same error | The PEP covers system-wide installs |
pip install --user |
Same error | The PEP says user installs are covered |
| A virtual environment exists but is not activated | The error, although .venv is present |
which python shows the system path |
| A script, Dockerfile or CI job calls the distribution's pip | Fails only on that host or image | The marker file exists in that image |
pipx installed with pip install --user |
The error while installing pipx itself | pipx's install page describes this case |
Prove the cause before changing anything
All of these only read.
1. Read the whole message. The lines between the message and the note come from the marker file and may name your distribution's package manager.
2. Check which Python you are using. The Python Packaging User Guide says that with a virtual environment active the path includes the .venv directory:
which python
A path ending in .venv/bin/python means a virtual environment is active. A system path means it is not.
3. Find the marker file. The PEP's example puts it in the standard library directory, /usr/lib/python3.9/EXTERNALLY-MANAGED in its Debian illustration. Our own advice is to list the matching paths on your system:
ls /usr/lib/python3*/EXTERNALLY-MANAGED
If the file is missing but the error appears, the interpreter's standard library directory is somewhere else, for example under another prefix; pip's source uses sysconfig.get_path("stdlib").
4. Decide whether you need a library or an application. A library for a script or project belongs in a virtual environment. A command-line tool such as a formatter belongs in pipx, which the Packaging guide describes as "creating a virtual environment for each package".
Fix
Create a virtual environment for the project
The Packaging User Guide gives the command: python3 -m venv .venv creates "a new virtual environment in a local folder named .venv".
First save the current state:
ls -A > ~/folder-before.txt
That command creates the file folder-before.txt in your home folder, which you own.
Risk: the next command creates a new .venv folder in the current directory. Nothing else changes, but a folder that is checked into version control by mistake should be excluded; the guide says to exclude it with .gitignore.
python3 -m venv .venv
Only if you need to back out: the only change is the new .venv folder, and ls -A compared with ~/folder-before.txt shows it. Removing that folder would delete the environment and everything installed in it, with no way to undo it, so this section gives no removal command.
Risk: the next command changes the PATH of the current shell, so python and pip in that shell point into the new environment until you run deactivate or close the shell.
Activate it:
source .venv/bin/activate
To undo it, only if you need to: deactivate changes the current shell back, so python and pip point at the system Python again and installs there meet the same error. Run deactivate, which the guide says leaves the environment; closing the shell also deactivates it. Check again with which python.
Install the package inside the environment
First save the current state:
python -m pip freeze > requirements-before.txt
pip's freeze page says it outputs "installed packages in requirements format".
Risk: the next command installs example-lib and its dependencies into the active virtual environment. The system Python is not touched while the environment is active.
python -m pip install example-lib
To undo it, only if you need to: uninstall the package, answer the confirmation, and compare python -m pip freeze with requirements-before.txt. Dependencies pulled in with it appear in that comparison and each is uninstalled the same way, with its own warning.
Risk, only to back out: the next command removes example-lib from the active virtual environment. Our own reading: the packages it pulled in stay until they are removed separately.
python -m pip uninstall example-lib
Install a command-line application with pipx
pipx's install page lists sudo apt install pipx for Ubuntu 23.04 or newer and sudo dnf install pipx for Fedora, and says to use the distribution package where one exists. It warns that pip install --user pipx fails on Ubuntu 23.04+, Debian 12+ and Fedora 38+ with the same error. Its warning box names apt install pipx and dnf install pipx as the distribution packages to use, and gives a virtual environment for pipx where no package exists. Installing pipx is a separate changing step that the install page covers; the steps below start once pipx is installed.
First save the current state:
pipx list --short > pipx-before.txt
Risk: the next command creates a separate environment for example-tool and places its commands in pipx's app directory, which must be on your PATH; the install page uses pipx ensurepath for that.
pipx install example-tool
To undo it, only if you need to: remove it with pipx, then compare pipx list --short with pipx-before.txt.
Risk, only to back out: the next command deletes the example-tool environment. pipx's page says it "deletes the environment and unlinks its apps".
pipx uninstall example-tool
Use the distribution's own package
The PEP's Debian illustration of the marker's text suggests installing a distribution-packaged library with apt, under a name of the form python3-xyz. The exact advice on your system is whatever the marker file's Error text says. No command is given here for it: installing a distribution package changes the system Python for every program that uses it, so it is a step for the system's administrator.
The override flag
pip's reference lists --break-system-packages as "Allow pip to modify an EXTERNALLY-MANAGED Python installation", also settable with PIP_BREAK_SYSTEM_PACKAGES. pip's own note says that using it is "at the risk of breaking your Python installation or OS", and the PEP says it should carry "some connotation that its use is risky". pip's pages give no safe command for it, so none is given here. If you must use it, the PEP's dnf and sudo pip uninstall examples describe what can go wrong. Do not set the environment variable for a whole machine.
Example (illustrative): On app01, an administrator runs pip install example-lib for a reporting script in /srv/example-app and gets error: externally-managed-environment. which python shows a system path, and ls /usr/lib/python3*/EXTERNALLY-MANAGED lists one file. The administrator runs python3 -m venv .venv in /srv/example-app, activates it, and installs the library there. which python now ends in .venv/bin/python, and the script runs with .venv/bin/python.
Confirm the fix
which pythonends in.venv/bin/pythonwhile the environment is active.python -m pip freezelistsexample-lib.- The script runs with the environment's interpreter, for example
.venv/bin/python script.py. - For pipx,
pipx list --shortlists the application.
What to watch afterwards
- Scripts, cron jobs and CI steps must call the virtual environment's
python, or activate it first. - After a Python upgrade, pipx's page describes
pipx reinstallas the way to rebuild a pipx environment. - Do not copy
--break-system-packagesfrom one host's notes to another.
Read next
Related articles you may want next.
- Troubleshootingnpm ERESOLVE "unable to resolve dependency tree": read the conflicting peer, then align, override or accept itnpm ERR! code ERESOLVE unable to resolve dependency tree? Read the Found and Could not resolve lines, then align versions or use overrides before any flag.Read article
- TroubleshootingNuGet NU1101 "Unable to find package": check the id, the configured sources and package source mappingNuGet NU1101 Unable to find package, no packages exist with this id in source(s)? Check the id, the nuget.config the build reads and source mapping.Read article
- TroubleshootingPowerShell "The term is not recognized as the name of a cmdlet, function, script file, or operable program": the module is not loadedPowerShell says the term is not recognized as a cmdlet, function, script file or program. Check spelling, list modules, then import or install it.Read article
Risks and limits
- These commands have not been run or lab-tested.
- The
lscheck for the marker is our own advice built from the PEP's example path; the standard library directory differs by system. - Which distributions ship the marker comes from pipx's page; check your own release.
- Dependencies of a package may remain after an uninstall until they are removed separately.
- pip's message text is a reading of version 24.3.1; other releases may word it differently.
Sources
- PEP 668 – Marking Python base environments as “externally managed” — Python Enhancement Proposals, last modified 15 June 2026, accessed 3 December 2026
- exceptions.py — pip source repository, tag 24.3.1, no date shown, accessed 3 December 2026
- misc.py — pip source repository, tag 24.3.1, no date shown, accessed 3 December 2026
- pip install — pip 26.3 documentation, no date shown, accessed 3 December 2026
- pip uninstall — pip 26.3 documentation, no date shown, accessed 3 December 2026
- pip freeze — pip 26.3 documentation, no date shown, accessed 3 December 2026
- Install packages in a virtual environment using pip and venv — Python Packaging User Guide, page dated 29 November 2026, accessed 3 December 2026
- Installing stand alone command line tools — Python Packaging User Guide, page dated 29 November 2026, accessed 3 December 2026
- Install pipx — pipx documentation, no date shown, accessed 3 December 2026
- Manage installed apps — pipx documentation, page dated 23 November 2026, accessed 3 December 2026
This article was originally published on .