Skip to content

Fix: pip error: no such option: --break-system-packages

FixDevs ·

Quick Answer

How to fix pip error no such option --break-system-packages caused by old pip versions, PEP 668 externally-managed environments, and virtual environment setup on modern Linux distributions.

The Error

You try to install a Python package and get:

error: externally-managed-environment

You follow advice to add --break-system-packages and get:

Usage: pip install [options] <requirement specifier> ...
no such option: --break-system-packages

Or:

ERROR: no such option: --break-system-packages

Your pip version is too old to support the --break-system-packages flag. This flag was added in pip 23.0.1 to work with PEP 668 (externally-managed Python environments), which is enforced by newer Linux distributions like Ubuntu 23.04+, Debian 12+, and Fedora 38+.

Why This Happens

Starting with PEP 668, modern Linux distributions mark their system Python as “externally managed.” This prevents pip from modifying system-wide packages, which could break the OS.

When you try pip install <package>, you get externally-managed-environment. The fix is supposed to be --break-system-packages — but this flag only exists in pip 23.0.1 and later. If your pip is older, the flag is not recognized.

Common scenarios:

  • Old pip in the system Python. The system pip is an older version that predates PEP 668 support.
  • Virtual environment not activated. You are using system pip instead of a virtual environment’s pip.
  • Pip installed via apt/dnf. The system package manager installed an old pip version.
  • Docker base image with old pip. The base image has an outdated pip.

The correct fix. Virtual environments bypass the externally-managed restriction entirely:

python3 -m venv myenv
source myenv/bin/activate
pip install <package>

Inside a virtual environment, pip installs packages into the venv’s isolated directory, not the system Python. No flags needed.

Create a venv in your project directory:

cd /path/to/project
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Deactivate when done:

deactivate

Pro Tip: Always use virtual environments for Python projects. They prevent conflicts between project dependencies and keep the system Python clean. This is not just a workaround — it is the intended workflow for Python development on modern systems.

If python3 -m venv itself fails, install the venv module:

# Ubuntu/Debian
sudo apt install python3-venv

# Fedora
sudo dnf install python3-virtualenv

For more on the externally-managed-environment error itself, see Fix: pip externally-managed-environment.

Fix 2: Upgrade pip

If you must use --break-system-packages (not recommended), upgrade pip first:

python3 -m pip install --upgrade pip

If this itself fails due to the externally-managed restriction:

# Download and run the pip installer directly
curl -sS https://bootstrap.pypa.io/get-pip.py | python3 --user

Or upgrade via the system package manager:

# Ubuntu/Debian
sudo apt install python3-pip

# Fedora
sudo dnf install python3-pip

After upgrading, verify the version:

pip --version
# pip 24.x.x from /usr/lib/python3/dist-packages/pip (python 3.12)

If pip is version 23.0.1 or higher, --break-system-packages is available.

Fix 3: Use pipx for CLI Tools

If you are installing command-line tools (like black, flake8, httpie), use pipx:

# Install pipx
sudo apt install pipx
# or
python3 -m pip install --user pipx

# Install CLI tools
pipx install black
pipx install httpie
pipx install poetry

pipx creates an isolated virtual environment for each tool automatically. The tools are available globally without touching the system Python.

List installed tools:

pipx list

Upgrade a tool:

pipx upgrade black

Fix 4: Use the —user Flag

Install packages in the user directory instead of system-wide:

pip install --user <package>

This installs to ~/.local/lib/python3.x/site-packages/, which does not require root and does not conflict with system packages.

Note: On newer systems with PEP 668, even --user might be blocked. The virtual environment approach (Fix 1) is the most reliable solution.

If the --user install works but the package is not found when you run it, add ~/.local/bin to your PATH:

export PATH="$HOME/.local/bin:$PATH"

Add this to your ~/.bashrc or ~/.zshrc to make it permanent. If Python itself is not found, see Fix: python command not found.

Fix 5: Fix Docker Containers

Docker images based on newer distributions also enforce PEP 668:

Broken:

FROM python:3.12-slim
RUN pip install flask  # May fail with externally-managed-environment

Actually, the official python Docker images do not mark Python as externally managed. But images based on ubuntu:24.04 or debian:12 do.

Fix for Ubuntu/Debian-based images:

FROM ubuntu:24.04

RUN apt-get update && apt-get install -y python3 python3-venv python3-pip

# Option 1: Use a virtual environment (recommended)
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN pip install flask

# Option 2: Remove the externally-managed marker (hacky)
# RUN rm /usr/lib/python3.*/EXTERNALLY-MANAGED
# RUN pip install flask

Common Mistake: Removing the EXTERNALLY-MANAGED file in Docker containers. While it works, it defeats the purpose of the safety mechanism. Use a virtual environment even in Docker — it is cleaner and matches production best practices.

Fix 6: Use conda or mamba

If you use Anaconda or Miniconda, use conda instead of pip:

conda install flask
conda install -c conda-forge black

Or use mamba for faster dependency resolution:

mamba install flask

Conda manages its own Python environments and does not interact with the system Python or PEP 668 restrictions.

As a last resort, you can globally allow --break-system-packages in pip’s config:

mkdir -p ~/.config/pip
cat > ~/.config/pip/pip.conf << 'EOF'
[global]
break-system-packages = true
EOF

Warning: This disables the PEP 668 protection permanently. If you install a package that conflicts with a system package, you could break your OS’s Python-dependent tools (like apt on Ubuntu). Only do this on development machines you can easily rebuild.

Still Not Working?

If you have tried all the fixes above:

Check which pip you are using:

which pip
which pip3
pip --version
pip3 --version

You might have multiple Python and pip installations. Make sure you are using the correct one.

Check for pyenv. If you use pyenv, the pyenv-managed Python is not externally managed and pip works normally:

pyenv install 3.12
pyenv local 3.12
pip install flask  # Works without restrictions

Check for snap-installed Python. On Ubuntu, snap install python3 installs a sandboxed Python. Use the system Python or pyenv instead.

Check pip cache issues. A corrupted pip cache can cause unexpected errors:

pip cache purge

For SSL certificate issues when pip tries to download packages, see Fix: pip SSL certificate verify failed.

If pip itself is missing entirely and you get ModuleNotFoundError: No module named 'pip', reinstall pip:

python3 -m ensurepip --upgrade

For general issues with pip failing to build packages, see Fix: pip could not build wheels.

F

FixDevs

Solo developer based in Japan. Every solution is cross-referenced with official documentation and tested before publishing.

Was this article helpful?

Related Articles