What the Error Means
On Debian 12 and later and Ubuntu 23.04 and later, pip install outside a virtual environment stops with error: externally-managed-environment and a hint to use apt or a virtual environment instead. The rule comes from PEP 668: the distribution places a marker file named EXTERNALLY-MANAGED in the standard library folder of the system Python, and pip 23.0 and later refuse to install there when they find it.
The reason is practical. Programs installed with apt depend on the python3- packages of the distribution. When pip replaces those libraries with other versions, apt-managed tools can break, and apt and pip then overwrite each other's files on every update. The system Python is 3.12 on Ubuntu 24.04 and 3.14 on Ubuntu 26.04.
Which Fix to Choose
| You need | Use |
|---|---|
| A library for a system script | apt package |
| Packages for your project | A venv |
| A command-line tool | pipx |
| A throwaway container | The flag, at most |
Fix 1: Install the Distribution Package
apt search python3-requests
sudo apt install python3-requests
Debian and Ubuntu name these packages python3- followed by the project name in lowercase. They are updated together with the rest of the system. On AlmaLinux and Rocky Linux, where the same advice applies to system scripts, the command is sudo dnf install python3-requests. Distribution packages can be older than the newest release on PyPI; if your code needs a newer version, use a virtual environment.
Fix 2: A Virtual Environment for Your Project
sudo apt install python3-venv
python3 -m venv ~/myproject/.venv
~/myproject/.venv/bin/pip install requests
Inside a virtual environment pip installs into the project's own folder, so the error does not appear. Activation, requirements.txt, and running the environment from systemd and cron are covered in Python venv.
Fix 3: pipx for Applications
For a Python program that you run as a command, pipx creates a separate environment for each tool and links the command into your PATH:
sudo apt install pipx
pipx ensurepath
pipx install black
Open a new shell after pipx ensurepath, then run the tool by name.
Why the Override Option Is a Last Resort
pip accepts --break-system-packages, an option that turns the check off for one command:
pip install --break-system-packages requests
It does what its name says. The packages land beside the distribution's own, nothing tracks them, and the next apt upgrade or pip run can leave either side broken. It is tolerable in a throwaway container or build image that is rebuilt from scratch and that nothing else depends on. On a long-lived server, use one of the three fixes above.
Do Not Delete the Marker File
Some advice online says to delete the EXTERNALLY-MANAGED file, which sits in /usr/lib/python3.12 on Ubuntu 24.04 and /usr/lib/python3.14 on Ubuntu 26.04. That has the same effect as the option above for every pip run, and the file belongs to a Python library package, so the next update of that package puts it back. Leave it in place.
Still Seeing the Error Inside a venv?
Then the pip you run is not the environment's pip. Common causes:
- The environment is not active: the prompt does not show its name. Activate it, or call
.venv/bin/pipdirectly. - sudo was used:
sudo pipruns the system pip with a different PATH. A venv in your own folder never needs sudo. - A different interpreter:
python3 -m pip --versionprints the path pip runs from; it must point inside the environment.
Installing pip and Python versions is covered in how to install pip on Ubuntu and how to install Python on Ubuntu.