Solved Error
How to Fix: pip error: externally-managed-environment
Quick Fix
Fastest fix: create and use a virtual environment instead of installing system-wide:
1. Run: python3 -m venv ~/venv
2. Activate it: source ~/venv/bin/activate (Linux/Mac) or ~\venv\Scripts\activate (Windows)
3. Install normally: pip install your-package-name
If you just want the old behavior back for a one-off script, add --break-system-packages to your pip command instead, but understand this can break your OS's Python tools.
What this error means
Starting with Python 3.11+ on distros like Debian 12 'Bookworm', Ubuntu 23.04+, Fedora 38+, and Homebrew-managed Python on macOS, your system now follows a rule called PEP 668. It proposes a way for distributors of a Python interpreter to mark that interpreter as having its packages managed by means external to Python, such that Python-specific tools like pip should not change the installed packages in the interpreter's global sys.path in any way unless specifically overridden.
In plain terms: your Python environment is managed by the operating system or a package manager, and direct installation using pip is restricted. You don't want a stray pip install breaking your operating system packages, that's the source of the error: you're trying to pip install into an environment managed by the Linux distribution.
You'll know it's this exact issue if you see a message like: error: externally-managed-environment × This environment is externally managed, often followed by a suggestion to use apt, brew, a venv, or pipx.
Step-by-Step Guide
Fix 1: Use a virtual environment (recommended for most people)
- 1Create the environment. This is the safest, most universally recommended fix and works the same way on Linux, macOS, and Windows. Run
python3 -m venv path/to/venv(use any folder name/path you like, e.g.~/myproject/venv). - 2Activate it. On Linux/Mac run
source path/to/venv/bin/activate. On Windows runpath\to\venv\Scripts\activate. - 3Install your package. Now run
pip install package-nameas normal — it installs only inside the venv, so it can't conflict with system packages. - 4Reactivate virtual environment for each terminal session. Remember to reactivate the venv every time you open a new terminal session to work on that project, since once deactivated, the packages you installed are no longer accessible in your environment, but you can access them again by reactivating the same virtual environment. On Debian/Ubuntu, if venv creation fails, install the full Python package first: make sure you have
python3-fullinstalled.
Fix 2: Install via your system's package manager
- 1Search for and install package via apt on Debian/Ubuntu. If you just need a common library and don't want a venv, install it through the OS instead of pip. On Debian/Ubuntu: search for the package name first, since the name of the system package may be different than the one that pip uses — typically Python packages are named
python3-<package>in Ubuntu. Then runsudo apt install python3-packagename. - 2Install package using Homebrew on macOS. On macOS with Homebrew: the error itself suggests this — to install Python packages system-wide, try
brew install xyz, where xyz is the package you are trying to install. - 3Understand system package manager version limitations. Trade-off to know: the system package manager may lag behind pip's latest release, since the version installed with pip is often more up-to-date than the one installed with apt, because the system package manager usually holds back packages while pip installs the latest version.
Fix 3: Use pipx for standalone command-line tools
- 1Install pipx via your package manager. If you're installing a Python application (a CLI tool) rather than a library for your own code, pipx is the recommended official approach. For example:
brew install pipxorsudo apt install pipx. - 2Install the tool with
pipx install xyzinstead of pip. For Python-based applications that can be used globally, the error message may recommend pipx — it automatically handles virtual environments for you, allowing you to run the application globally without interfering with the system-wide Python environment.
Fix 4: Force the install with --break-system-packages (use with caution)
- 1Run install with
--break-system-packagesflag. This overrides the protection and restores old pip behavior. It's the fastest option but carries real risk. Run the install with the flag:pip install package-name --break-system-packages(orpython -m pip install package-name --break-system-packages). - 2Make
--break-system-packagespermanent in configuration. To make it permanent (not recommended for most users) runpython3 -m pip config set global.break-system-packages true. - 3Understand the risk: this parameter forces pip to install packages directly into the system environment, which is faster but carries the risk of causing version conflicts with OS-level software. If you use it on Homebrew's Python, also pass
--useras recommended, since if you disable this error, it's strongly recommended to additionally pass the--userflag to pip, or setuser = trueinpip.conf, because failure to do this can result in a broken Homebrew installation.
Advanced: delete the EXTERNALLY-MANAGED marker file
The restriction is enforced by a single marker file, and some advanced users just remove it, though this is the most aggressive option.
1. Locate it in your Python's stdlib directory, e.g. /usr/lib/python3.11/EXTERNALLY-MANAGED — this error arises when pip installs outside of a virtual environment and a marker file, EXTERNALLY-MANAGED, exists in Python's stdlib directory, usually located in /usr/lib/<python_version>.
2. Delete it with sudo rm /usr/lib/python3.xx/EXTERNALLY-MANAGED. After this, now you should be able to install packages seamlessly with pip or pip3.
3. Note: this is a system-wide, permanent change until the file is recreated (e.g. on the next OS update), and it removes the safety net entirely — prefer the venv or pipx approaches unless you fully understand the trade-off.
If you're inside Docker
Inside containers the same error can appear even though isolation is already handled at the container level. Three options work well here: add --break-system-packages to your Dockerfile's pip install line (safe since containers are disposable), delete the EXTERNALLY-MANAGED file in the image, or switch your base image to a slim variant, since images like python:3.12-slim don't include the externally managed marker at all, so the error never appears — if you're starting a new project, this is often the simplest path.
When to get further help
If none of these fixes work, or you get a different underlying error after applying one of them (e.g. permission errors, missing python3-venv module, or a broken Homebrew install), the issue is likely specific to your OS setup or a corrupted Python install. In that case check your distribution's official documentation or package manager support channels, or consider reinstalling Python cleanly for your platform.
Sources:
- How to Fix “error: externally-managed-environment” in Pip | Built In
- Fix externally-managed-environment Error
- Fixing externally-managed-environment Error While Installing With pip | Baeldung on Linux
- How to solve "error: externally-managed-environment" when installing via pip3 - Jeff Geerling
- “Externally managed environments”: when PEP 668 breaks pip
- PEP 668 – Marking Python base environments as “externally managed” | peps.python.org
- How to Fix the pip "externally-managed-environment" Error on Linux
- error: externally-managed-environment - Semgrep
Heads up: this guide was drafted with AI assistance from the real sources listed below, and structured by our team for clarity. It may not cover every possible cause — if it doesn't fix your issue, let us know and we'll take a closer look. See how we create our fixes.
Was this fix helpful?
Related Error Fixes
- How to Fix: pip 'Could not build wheels for ...' ErrorPython
- How to Fix: ModuleNotFoundError: No module named '...'Python
- How to Fix: 'blocked by CORS policy: No Access-Control-Allow-Origin header is present'CORS
- How to Fix: "Cannot read properties of undefined (reading '...')"JavaScript
- How to Fix Git Error: "refusing to merge unrelated histories"Git