Fix the Externally Managed Environment Pip Error
Externally Managed Environment Pip: How to Fix the Error and Install Packages Safely
To bypass the externally managed environment error in pip, you create an isolated virtual environment. Use python3 -m venv venv and activate it before installing packages. Modern Linux distributions and Python installations implement PEP 668, placing an EXTERNALLY-MANAGED marker file in the system site-packages directory. This restriction stops pip from modifying global system packages and breaking core operating system tools.
Why does pip throw the externally managed environment error?
An externally managed environment in Python refers to an installation. The operating system or another external package manager, rather than pip, controls its global package installation context. When pip 23.0 or later detects this packaging boundary, it refuses to install, uninstall, or upgrade packages globally (pip.pypa.io). Debian 12+, Ubuntu 23.04+, Fedora 38+, and Homebrew on macOS have adopted PEP 668 to protect system stability (pipx.pypa.io).

How to fix externally managed environment pip on Ubuntu and Debian
You set up a local workspace directory and run Python’s built-in virtual environment module to isolate your project dependencies.
- Open your terminal and navigate to your project directory.
- Run
python3 -m venv venvto create a new virtual environment folder named venv. - Activate the environment by running
source venv/bin/activateon Linux or macOS. - Confirm the activation succeeds when your terminal prompt changes to display
(venv). - Install your required packages using standard
pip install package_namecommands safely inside the isolated scope.
How to install command-line applications with pipx
For installing global command-line tools without violating system package policies, you use pipx. This tool provisions isolated virtual environments automatically for each executable. Standard global installations fail under PEP 668, and running sudo pip install introduces severe security risks and permission issues. Instead, you install pipx via your system package manager and let it manage your CLI utilities.
sudo apt install pipx
pipx ensurepath
pipx install shelliest
Externally managed environment pip on macOS, WSL, Raspberry Pi, and Docker
Different environments handle PEP 668 in specific ways depending on how Python is packaged. On macOS, Homebrew installs Python as an externally managed environment. Users must use virtual environments or pipx instead of global pip commands. Windows Subsystem for Linux (WSL) distributions like Ubuntu enforce PEP 668 identically to bare-metal Linux installations. Raspberry Pi OS uses Debian as its base, meaning modern versions trigger the same global package protection. Inside Docker containers, you often run lightweight or single-purpose images. Users control the entire container lifecycle, making tool usage simpler.

When should you use the break system packages flag?
The --break-system-packages flag overrides the PEP 668 restriction, but you must avoid using it on persistent operating systems. Appending this flag forces pip to write directly to the system-managed environment. Such actions frequently corrupt OS-level Python dependencies and break package managers like Apt or Dnf. You only apply this flag inside disposable environments like Docker containers where system stability carries no consequences.

Related guides
Frequently asked questions
Can I use pip install –user to bypass the error?
Using pip install --user fails as a workaround because modern pip and operating system combinations enforce the PEP 668 restriction across user-level site-packages directories as well.
Does this error affect Python virtual environments?
No, the externally-managed-environment restriction only targets global system Python installations and never triggers inside properly activated virtual environments.
How do I check if my Python environment is externally managed?
You inspect your Python standard library directory for an EXTERNALLY-MANAGED marker file. Alternatively, you test a global pip installation command to see if the error message appears.
What should you do if pip3 install still fails after creating a virtual environment?
You verify that your virtual environment is actively enabled by checking your terminal prompt for the environment name. Next, confirm that the which pip command points to your local project folder rather than a system directory.
Who should avoid using virtual environments for pip packages?
Developers who need system-wide command-line executables skip standard virtual environments and choose pipx instead. This tool installs CLI tools into isolated environments while exposing their binaries globally.