error: externally-managed-environment (pip): how to fix it
error: externally-managed-environment means pip found an EXTERNALLY-MANAGED marker in the Python it was about to install into: that Python belongs to your operating system's or Homebrew's package manager (PEP 668), and pip will not change it outside a virtual environment. Install into a virtual environment instead (python3 -m venv .venv), use pipx for command-line tools, or build on the official python Docker image; --break-system-packages is the last resort.
By Livops team, the people who build and run LivopsUpdated
pip ends with this when the Python you run it with is managed by something else. The lines are pip’s own[3]; the text after ╰─> comes from the Python’s distributor, here the opening of Debian’s message as PEP 668 gives it[1]:
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
...
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
On another distributor’s Python the text under ╰─> is whatever its marker file says; when the marker gives none, pip prints its default, which starts The Python environment under /usr is managed externally with your Python’s prefix in place of /usr[3]. Same error, same fixes. This page explains the marker file behind it, gives the fixes in the order we would try them, and says what Livops does.
What does the error mean?
PEP 668 lets a distributor mark a Python installation as externally managed: its packages belong to a package manager such as apt or Homebrew, not to pip[1]. The mark is a file named EXTERNALLY-MANAGED in the standard library directory, the one sysconfig.get_path("stdlib", sysconfig.get_default_scheme()) returns[2]. You can see it yourself:
python3 -c 'import sysconfig; print(sysconfig.get_path("stdlib", sysconfig.get_default_scheme()))'
ls "$(python3 -c 'import sysconfig; print(sysconfig.get_path("stdlib", sysconfig.get_default_scheme()))')"/EXTERNALLY-MANAGED
An installer refuses only when both are true: it is running outside a virtual environment, and the file exists[2]. Inside a virtual environment the marker does not apply; the check is whether sys.prefix equals sys.base_prefix[1]. pip has read the marker since pip 23.0[6].
Why distributions do this
The PEP’s reason is conflicts between the operating system’s package manager and Python tools like pip: a pip install into the system Python can replace or remove files the distribution owns and break its own tools written in Python[1]. So the system Python is left to the system, and your packages go somewhere that is yours.
Who ships the marker:
- Debian declares its Python externally managed, so pip refuses to install system-wide, and installing into your home directory with
pip install --useris disabled by the same policy[7]. - Homebrew marks its current Python as externally managed and says to install project dependencies in a virtual environment instead of its base environment[8].
Fix 1: install into a virtual environment
This is the fix the specification itself points to: an installer’s default message should suggest creating a virtual environment[2]. In the project folder:
python3 -m venv .venv
.venv/bin/python -m pip install -r requirements.txt
.venv/bin/python main.py
You do not need to activate the environment: running its own Python by path is enough, and scripts installed into it run without activating[9]. To work in it interactively, source .venv/bin/activate[9].
On Debian, the venv module comes in the separate python3-venv package[7]:
sudo apt install python3-venv
Keep .venv out of git. A virtual environment is not movable or copyable; you recreate it where it runs, and since Python 3.13 venv writes a .gitignore into it for you[9].
Fix 2: pipx for command-line tools
If what you are installing is a program, not a library for your code (black, httpie, yt-dlp and the like), use pipx. It creates a virtual environment for each package and puts its commands in a directory on your PATH[10]. Debian recommends it for Python applications it does not package[7], and Homebrew for command-line applications that should each have an isolated environment[8]:
brew install pipx # macOS with Homebrew
pipx install black
On Linux, install pipx from your distribution’s package manager.
Fix 3: the official python image in Docker
The error in a Dockerfile usually means the image got its Python from the distribution, for example FROM debian and apt-get install python3-pip; then the distribution’s marker comes with it. The official python images compile CPython from source, put it on /usr/local/bin, and their Dockerfile has no step that writes an EXTERNALLY-MANAGED file[11]. Build on one of them:
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "main.py"]
If you must stay on a distribution image, create a virtual environment in it and install there, as in Fix 1. PEP 668 also covers this case: a distributor may leave the marker out of a single-application image that is not updated after it is built, but is advised to keep it in images where users install package updates[1][2].
Last resort: –break-system-packages
pip has an override, as the specification asks installers to have, off by default and named to signal the risk[2]. --break-system-packages lets pip modify an externally managed installation[5]; it arrived in pip 23.0.1[6].
pip install --break-system-packages requests
pip’s own message offers it “at the risk of breaking your Python installation or OS”[3], and Debian says you do it at your own risk, since pip may break the Python modules Debian packages[7]. Like any pip option it can also be set as the variable PIP_BREAK_SYSTEM_PACKAGES=1[12][7], which turns it on for every pip command that sees the variable. Use it in a throwaway container or CI job, never on a server you care about.
Two things that are not fixes:
pip install --useris checked like a system install: pip skips the check only for--target,--prefixand--rootinstalls[4], and on Debian user installs are disabled by the same policy[7].- Deleting the
EXTERNALLY-MANAGEDfile is the same risk as the flag, made permanent for everything that uses that Python. Use a virtual environment instead.
How to confirm the fix locally
Check that the pip you run is the environment’s, not the system’s:
.venv/bin/python -m pip --version
.venv/bin/python -c 'import sys; print(sys.prefix != sys.base_prefix)'
The first line names a path inside .venv, and the second prints True inside a virtual environment[1]. Then install your requirements with that pip; with the marker out of the way, any error left is about the packages themselves.
On Livops
-
You do not install into a system Python. Livops installs your dependencies itself, and the commands run from the project’s
.venv: a start command you write in Settings → Start begins with.venv/bin/, for example.venv/bin/python main.py, and aProcfileline readsworker: .venv/bin/python bot.py. -
Do not upload your
.venv. When you upload a folder,venvand.venvare dropped automatically; we install dependencies ourselves. -
Your own Dockerfile. The
Dockerfileis used by default when no framework was recognised; to build a recognised Python project from it instead, add"builder": "dockerfile"tolivops.jsonbefore the project is created. If it installs Python withapt, start itFROM python:3.12-sliminstead (Fix 3), or install into a virtual environment inside the image.{ "builder": "dockerfile" } -
When an install fails, the deploy stops as
install_failed, the build log shows pip’s output, and the old version keeps running. Next to the failed build, the assistant’s button reads the log and explains it. -
Choose the Python. Livops runs Python 3.10 to 3.14. A
.python-versionfile at the project root pins it:3.12
A Python web app costs 39 credits a month; a bot, worker or cron job 19. When pip cannot find a package at all, see No matching distribution found; the install errors are in Install failed.
Questions
Is this a bug in pip?
No. pip is following PEP 668: the Python you are installing into carries an EXTERNALLY-MANAGED marker file, which says its packages are managed by another tool, such as apt or Homebrew. pip refuses on purpose and points you at a virtual environment.
Why did pip install work before and stop now?
pip has read the marker since pip 23.0. If the same command used to work, either your pip was older than that, or the Python you installed into had no EXTERNALLY-MANAGED file at the time.
Does pip install --user avoid the error?
No. A --user install still goes into the externally managed interpreter's environment, so pip checks the marker and refuses. Debian's own notes say user installs are disabled by the same policy. Use a virtual environment.
Is --break-system-packages safe?
It does what its name says. pip's own message offers it at the risk of breaking your Python installation or OS, and Debian warns pip may break the Python modules it packages. Use it only in a throwaway container or a machine you are willing to rebuild.
Do I get this error inside a virtual environment?
No. The marker applies only outside a virtual environment. If you still see it, the pip you ran is not the one in the environment: call .venv/bin/python -m pip, or activate the environment first.
Does the official python Docker image have this error?
Its Python is compiled from source into /usr/local, and its Dockerfile writes no EXTERNALLY-MANAGED marker, so pip install works there. Images that install Python from the distribution, such as apt-get install python3-pip on a Debian image, bring the marker with them.
Which Python versions does Livops run?
Python 3.10 to 3.14. Put the version in a .python-version file at the project root, for example 3.12.
Sources
- PEP 668 — Marking Python base environments as "externally managed" (peps.python.org). Checked .
- Python Packaging User Guide — Externally Managed Environments (packaging.python.org). Checked .
- pip source — src/pip/_internal/exceptions/__init__.py (ExternallyManagedEnvironment) (raw.githubusercontent.com). Checked .
- pip source — src/pip/_internal/commands/install.py (raw.githubusercontent.com). Checked .
- pip docs — pip install (pip.pypa.io). Checked .
- pip docs — Changelog (pip.pypa.io). Checked .
- Debian python3 package — README.venv (salsa.debian.org). Checked .
- Homebrew docs — Language runtimes and packages (docs.brew.sh). Checked .
- Python docs — venv (docs.python.org). Checked .
- Python Packaging User Guide — Installing stand alone command line tools (packaging.python.org). Checked .
- docker-library/python — Dockerfile-linux.template (raw.githubusercontent.com). Checked .
- pip docs — Configuration (pip.pypa.io). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your Python appRelated
- pip: Could not find a version that satisfies the requirement / No matching distribution found — how to fix itERROR: Could not find a version that satisfies the requirement X (from versions: none), followed by No matching distribution found for X, means pip searched the package index and found no release of X it can install here. The name is wrong (often the import name instead of the package name), the pinned version does not exist, every release needs a different Python, no file fits your platform, or pip is looking at the wrong index or cannot reach it. The versions list in the message tells you which.
- ModuleNotFoundError: No module named — after a deployPython searched sys.path and could not find the module you import. After a deploy that almost always means the package is not in requirements.txt, is listed under a different name than the one you import, or the start command runs a Python that the packages were not installed into.
- pip: Failed building wheel / failed-wheel-build-for-install — how to fix itpip found no ready-made wheel for a package on your Python version and platform, tried to compile one from source, and the compiler step failed. The fix is almost never to install a compiler: move to a version of the package that ships a wheel for your Python, switch to its binary variant (psycopg[binary], psycopg2-binary), or pin the Python version the package supports.
- Error: pg_config executable not found (psycopg2): how to fix itError: pg_config executable not found, followed by Failed building wheel for psycopg2, means pip is compiling psycopg2 from source and the machine has no PostgreSQL client headers or pg_config. Switch to a package that needs no compiling, psycopg2-binary or psycopg[binary] for Psycopg 3, or install libpq-dev and a C compiler where the build runs.
- How to run a Python script 24/7 (and keep it running)A script started in a terminal stops when the terminal closes, the SSH connection drops or the laptop sleeps. To keep it running you need something that starts it again: a systemd service with Restart=always, Docker with a restart policy, or a platform's background worker. On Livops it runs as a worker for 19 credits a month (19,000 so'm).
- Django hosting in 2026: how to deploy a Django app, and whereFor most Django apps, a platform that deploys from Git is the right pick: Render and DigitalOcean App Platform are the simplest fixed monthly prices, Fly.io is the cheapest in dollars, Railway bills by usage, and a VPS is for when you want root. Livops fits Django apps whose users are in Uzbekistan, at 39 credits a month. Below: prices and free tiers side by side, a Django deployment checklist, and how to host a Django project on Livops.
- FastAPI hosting in 2026: how to deploy a FastAPI app, and whereA FastAPI app in production runs on Uvicorn without --reload, listens on 0.0.0.0 and the platform's port, trusts the proxy's headers and runs its migrations before it starts. On Livops a repository with main.py and requirements.txt starts on Uvicorn from a push, for 39 credits a month (39,000 so'm). Here is how Render, Railway, Fly.io and a VPS compare.
- AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK': how to fix itAttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK', raised from OpenSSL/crypto.py, means an old pyOpenSSL is installed next to a newer cryptography. pyOpenSSL 20.0.1 and older read that constant as they load, and cryptography 38.0.0 removed it. The same mismatch shows as 'OpenSSL_add_all_algorithms', 'X509_V_FLAG_NOTIFY_POLICY' or 'GEN_EMAIL'. Upgrade pyOpenSSL, or uninstall it if nothing needs it, and pin versions that fit together.