Skip to content
Node.js and Python3 min read

pip error: externally-managed-environment

error: externally-managed-environment

Short answer

externally-managed-environment means pip refused to install into the operating system's own Python, because the OS manages those packages (PEP 668). Create a virtual environment with `python3 -m venv .venv`, activate it and install there; use `pipx` for command-line tools, or the distribution's package (`apt install python3-xyz`).

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. Where you’ll see it
  2. Causes
  3. How to fix it
  4. Prevention
  5. On ArabyHost

Linux distributions use Python for their own tools, and they install Python packages with their package manager (apt). When pip also installs into the same place, the two can overwrite each other’s files. PEP 668 lets a distribution mark its Python as “externally managed”, and recent pip versions then refuse system-wide installs with this message:

error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.

The error isn’t a bug. It’s the system pointing you to a virtual environment.

Where you’ll see it

  • Debian 12 and later, and Raspberry Pi OS based on it.
  • Ubuntu 23.04 and later, including Ubuntu 24.04.
  • Homebrew’s Python on macOS, and several other distributions.

Causes

  • Running pip install or pip3 install outside any virtual environment.
  • A script or tutorial written for older systems that installs packages globally.
  • A Dockerfile based on a Debian or Ubuntu image that calls the system pip.
  • Believing a virtual environment is active when it isn’t (the prompt doesn’t show its name).

How to fix it

  1. Create and use a virtual environment (recommended for any project):

    python3 -m venv .venv
    source .venv/bin/activate
    pip install -r requirements.txt

    Inside the environment, pip installs normally. Run your app with .venv/bin/python, or after activating.

  2. If venv itself fails with “ensurepip is not available”, install the missing module: sudo apt install python3-venv.

  3. For command-line tools you want everywhere (formatters, downloaders), use pipx, which gives each tool its own environment:

    sudo apt install pipx
    pipx install black
  4. For a library a system script needs, install the distribution’s package: sudo apt install python3-requests. It may be an older version than the one on PyPI.

  5. --break-system-packages is the last resort. It bypasses the protection, and pip may then overwrite files the OS relies on. Use it only in disposable containers, never on a server you care about.

  6. In Docker, either start from an official python image, where pip works normally, or create a venv in the image and put its bin folder first in PATH.

Don’t delete the EXTERNALLY-MANAGED marker file to silence the error: it hides the problem and is restored on the next system update.

If packages are installed but your code still can’t import them, see ModuleNotFoundError.

Prevention

  • Start every project with a virtual environment and a requirements.txt.
  • Keep system Python for the OS, and your apps in their own environments.
  • Update old install scripts to create a venv first.

On ArabyHost

On ArabyHost AI/Developer plans there’s no root access, so system-wide installs aren’t possible in any case; your packages always belong in a virtual environment. cPanel’s Setup Python App creates one for each app (Python 3.9 to 3.12). Enter it over SSH with the command shown at the top of the app’s page, then pip install -r requirements.txt works without this error. See Python hosting for what the plans support.

FAQ

Is it safe to use --break-system-packages?

It's safe only in a throwaway environment such as a disposable container. On a real system, pip can replace packages that the OS tools depend on, and a later update or system command may break.

Does pip install --user avoid the error?

No. On systems that adopted PEP 668, user installs into the system Python are blocked too. Use a virtual environment or pipx instead.

python3 -m venv fails with ensurepip is not available. What now?

On Debian and Ubuntu the venv module ships separately. Install it with `sudo apt install python3-venv` (or the versioned package such as `python3.12-venv`), then create the environment again.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.