pypipip95% confidence\u2191 1042

How do I solve "error: externally-managed-environment" every time I use pip 3?

Full error message
When I run pip install xyz on a Linux machine (using Debian or Ubuntu or a derived Linux distribution), I get this error:

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.

    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.

    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.

    See /usr/share/doc/python3.11/README.venv for more information.

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.

What does this error mean? How do I avoid it? Why doesn't pip install xyz work like it did before I upgraded my system using sudo apt upgrade?

The proper way to install Python libraries and applications is to install them in a Python virtual environment whenever possible (the exceptions to this rule are quite rare). The error message describes two common ways to accomplish this: either by creating a virtual environment yourself, or for applications, by using pipx—a tool which will create a virtual environment for you and install the application in that virtual environment. pipx is strongly recommended for installing applications, i.e., when you will primarily use the installed code from the command line. On Debian systems and Debian-based systems such as Ubuntu, you can install pipx using apt, and then use pipx to install the application: apt install pipx pipx install some-python-application For libraries, i.e., when you will use the code primarily by importing it in your own projects. Typically, you should create a virtual environment yourself. You can do this with venv from the standard library: python -m venv my-venv my-venv/bin/pip install some-python-library See also this answer on a duplicate question for more details. (Commonly, your own project may need several libraries. Make one virtual environment and install the libraries that your project needs side by side in that virtual environment.) If you know you don’t need to use your system long-term (e.g. because you’re working in a container or CI environment like Docker or GitHub Actions), and you're still sure that you want to install packages "system-wide" and risk breaking your system (for example, by overwriting libraries that were part of tools written in Python that came with your system), Pip needs to be given permission to do so. There are a few ways to do this: For a single use of pip, add the --break-system-packages argument to the command. Add these lines to ~/.config/pip/pip.conf (this will enable every future run of Pip to break system packages: [global] break-system-packages = true Use Pip's config command to edit the above file (credit to The Matt from the comments): python3 -m pip config set global.break-system-packages true Theoretically, removing or renaming the "marker" file (/usr/lib/python3.x/EXTERNALLY-MANAGED) would also disable the block, but this is a bad idea. The file was put there for a reason, and it's at least as easy to use the intended mechanisms instead.

API access

Get this solution programmatically \u2014 free, no authentication.

curl https://depscope.dev/api/error/6bfa436e11d566998910b15ee0bdf04a34a0a1a27e516a923aa2a51524eca359
hash \u00b7 6bfa436e11d566998910b15ee0bdf04a34a0a1a27e516a923aa2a51524eca359
How do I solve "error: externally-managed-environment&q… — DepScope fix | DepScope