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.

Answer from maciek97x on Stack Overflow
Top answer
1 of 16
776

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.

2 of 16
338

I have had this error since Python 3.11+.

I resolved it by moving the EXTERNALLY-MANAGED file elsewhere:

sudo mv /usr/lib/python3.11/EXTERNALLY-MANAGED /usr/lib/python3.11/EXTERNALLY-MANAGED.old

As Alok and JackLeEmmerdeur warn:

This deletion of file is not safe. This can lead to Broken Package Management, Conflicting Installations and Permission Issues

If that occurs, this change can be reverted by moving the .old file back.

🌐
Built In
builtin.com › articles › error-externally-managed-environment
How to Fix “error: externally-managed-environment” in Pip | Built In
April 28, 2026 - Error: externally-managed-environment occurs when a package manager is managing a Python environment, which prevents direct use of pip. It can be solved using a virtual environment: python3 -m venv ~/py_envs source ~/py_envs/bin/activate python3 ...
Discussions

The most popular advice on the internet for `error: externally-managed-environment` is to force packages to be system installed - Packaging - Discussions on Python.org
This is more of an informational than a call to action, as I don’t know what that call to action would be on the Python packaging side. But someone recently reported to pip issue they were getting error: externally-managed-environment: *Error: externally managed environment* · Issue #12809 ... More on discuss.python.org
🌐 discuss.python.org
8
June 28, 2024
While in a Python venv I get -> error: externally-managed-environment when using sudo
Python venv sourcing is not working properly in Manjaro (?) $cd /data $which python /usr/bin/python $sudo -u user python -m venv project $cd project $source bin/activate (313)$ sudo -u user pip install -U pip ... More on forum.manjaro.org
🌐 forum.manjaro.org
1
0
March 19, 2025
How do I fix the "error: externally-managed-environment" whenever I try to pip install something on my Raspberry Pi?
Newer versions of Python really don't like you trying to install packages globally using pip. Especially on operating systems that depend upon specific versions of Python being installed, as many Linux distributions do. As for how to address the issue, it's pretty much what the message says: either use your OS's package manager to install the package, or create a virtual environment and install into that environment using pip. Virtual environments are generally speaking a Good Thing anyway, so do that. More on reddit.com
🌐 r/learnpython
4
1
May 16, 2024
Trying to understand Externally Managed Environment
the Python interpreter used by the system… is for the system. Project dependencies in a mess that will never really be solved natively in Python, as with any other dynamic language that doesn’t ship libraries compiled. you can always use pipx to install system wide tools on the PATH associated with its own venv. More on reddit.com
🌐 r/learnpython
9
4
March 22, 2024
People also ask

How can I resolve the "externally-managed environment error" when using pip?
To resolve an "externally-managed environment error" when using pip, you can use a virtual environment, install using the system’s package manager, or force install it with specific commands.
🌐
decodo.com
decodo.com › blog › externally-managed-environment
Fix externally-managed-environment Error
Why does my Docker container throw an "externally-managed environment error"?
Docker often manages the environment internally to ensure consistency and reproducibility. This can lead to restrictions on installing or modifying packages in ways that conflict with the container's base image or configuration. To resolve this, you can modify the dockerfile and add specific instructions to handle package installations properly or use a virtual environment within Docker. See the article for a full list of solutions.
🌐
decodo.com
decodo.com › blog › externally-managed-environment
Fix externally-managed-environment Error
🌐
Reddit
reddit.com › r/learnpython › pip3 environment externally managed
r/learnpython on Reddit: Pip3 Environment Externally Managed
September 10, 2024 -

Hello, I have recently been trying to install the pyautogui using pip like normal. When I encountered the environment was externally managed error. I tried multiple times and I have never found a solution. I even made a venv and tried to run the command in there. I don't know if I was doing it wrong but it still showed me the error. I reinstalled pip, same thing. I delete pip and python, reinstall both no difference. I even tried brew to see if there was a way to download it, nothing. I would greatly appreciate any sort of help thank you very much.

error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
    xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a Python library that isn't in Homebrew,
    use a virtual environment:
    
    python3 -m venv path/to/venv
    source path/to/venv/bin/activate
    python3 -m pip install xyz
    
    If you wish to install a Python application that isn't in Homebrew,
    it may be easiest to use 'pipx install xyz', which will manage a
    virtual environment for you. You can install pipx with
    
    brew install pipx
    
    You may restore the old behavior of pip by passing
    the '--break-system-packages' flag to pip, or by adding
    'break-system-packages = true' to your pip.conf file. The latter
    will permanently disable this error.
    
    If you disable this error, we STRONGLY recommend that you additionally
    pass the '--user' flag to pip, or set 'user = true' in your pip.conf
    file. Failure to do this can result in a broken Homebrew installation.
    
    Read more about this behavior here: <https://peps.python.org/pep-0668/>
Top answer
1 of 6
57

There's a good article on OMGUbuntu about this: 3 Ways to Solve Pip Install Error on Ubuntu 23.04

Here's the summary. There are three ways to approach this problem:

1. Install the Python package using APT

For instance, if you want to install the requests Python library, you can install it using APT instead, like this:

sudo apt install python3-requests

This will install this library system-wide.

Not all packages available on PyPI have been packaged and included in the Debian/Ubuntu repositories, so this method won't work for some packages.

Or: 2. Create a virtual environment using venv or virtualenv

Make sure venv is installed by running:

sudo apt install python3-venv

To create a new virtual environment in a directory named .venv, run:

python3 -m venv .venv

To activate this virtual environment (which modifies the PATH environment variable), run this:

source .venv/bin/activate

Now you can install a library like requests in this virtual environment:

pip install requests

The files will get installed under the .venv/ directory.

If you want to leave the virtual environment, you can run:

deactivate

If you don't want to run source .venv/bin/activate and deactivate, then you can run the executable by prefixing its path, like this:

 $ .venv/bin/pip install requests
 $ .venv/bin/python3
 >>> import request
 >>> help(requests)

Or: 3. Use pipx

pipx lets you install and run Python applications in isolated environments. This is the recommended way to install PyPI packages that represent command-line applications.

To install pipx, run:

 sudo apt install pipx

pipx needs ~/.local/bin/ to be in your PATH. You can automatically modify your shell configuration (such as ~/.bashrc) to modify PATH appropriately by running:

 pipx ensurepath

(You may need to close your terminal application and open it again for the changes to take effect.)

Now you can install a package from PyPI, like this:

 pipx install pycowsay

And you can run the command that you just installed, like this:

$ pycowsay Mooo!

  -----
< Mooo! >
  -----
   \   ^__^
    \  (oo)\_______
       (__)\       )\/\
           ||----w |
           ||     ||

As you can see, pipx installed a symlink in ~/.local/bin/ to the executable in a virtual environment:

$ ls -l ~/.local/bin/pycowsay
lrwxrwxrwx 1 flimm flimm 50 May 24 11:19 /home/flimm/.local/bin/pycowsay -> /home/flimm/.local/pipx/venvs/pycowsay/bin/pycowsay*

Or: 4. Pass --break-system-packages flag:

If you want to ignore the warning, you can pass the --break-system-packages flag:

pip install --break-system-packages --user <foobar>

This method is not recommended, because you may find yourself with mysterious broken installations of Python packages months or years later, after you've forgotten that you used --break-system-packages and installed other conflicting Python packages.

2 of 6
12

In a terminal, delete this file with:

sudo rm /usr/lib/python3.11/EXTERNALLY-MANAGED

and everything will be OK!

🌐
Semgrep
semgrep.dev › docs › kb › semgrep-appsec-platform › error-externally-managed-environment
error: externally-managed-environment - Semgrep
April 28, 2026 - If your Python environment is externally managed by a package manager, you can't use pip for system-wide installations. This results in the externally-managed-environment when you try to use pip to install Semgrep.
🌐
Decodo
decodo.com › blog › externally-managed-environment
Fix externally-managed-environment Error
April 6, 2026 - The externally-managed-environment error in Python occurs when you attempt to use pip to install packages in a Python environment that is managed by an external system, such as an operating system package manager or a bundled Python environment ...
Find elsewhere
🌐
Baeldung
baeldung.com › home › installation › fixing externally-managed-environment error while installing with pip
Fixing externally-managed-environment Error While Installing With pip | Baeldung on Linux
May 11, 2024 - To be more exact, this error arises when pip installs outside of a virtual environment and a marker file, EXTERNALLY-MANAGED, exists in Python’s stdlib directory: $ ls /usr/lib/python3.11 .. enum.py EXTERNALLY-MANAGED filecmp.py ...
🌐
Jeff Geerling
jeffgeerling.com › blog › 2023 › how-solve-error-externally-managed-environment-when-installing-pip3
How to solve "error: externally-managed-environment" when installing via pip3 - Jeff Geerling
August 30, 2023 - For macOS, use find /opt/homebrew -name EXTERNALLY-MANAGED to find the location (or find /usr/local -name EXTERNALLY-MANAGED on Intel Macs) See this answer on Stack Overflow for more. Another interesting option is to install and use pipx, which does the grunt work of managing the venvs for you.
🌐
Python.org
discuss.python.org › packaging
The most popular advice on the internet for `error: externally-managed-environment` is to force packages to be system installed - Packaging - Discussions on Python.org
June 28, 2024 - This is more of an informational than a call to action, as I don’t know what that call to action would be on the Python packaging side. But someone recently reported to pip issue they were getting error: externally-managed-environment: *Error: externally managed environment* · Issue #12809 · pypa/pip · GitHub To me the error looked very clear, but obviously the user did not know how to handle it, hence them reporting the issue.
🌐
Mac Install Guide
mac.install.guide › python › externally-managed-environment
Fix error: externally-managed-environment on Mac · 4 Ways · 2026
April 27, 2026 - It protects your system Python from package conflicts and partially-broken upgrades. The fix is not to bypass the protection. The fix is to install your packages somewhere else (uv, pipx, or a virtual environment).
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › python
error: externally-managed-environment - Raspberry Pi Forums
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 ...
🌐
99RDP
99rdp.com › home › blog › linux › fixing the “this environment is externally managed” error in pip
Fixing the “This Environment Is Externally Managed” Error in Pip
November 14, 2024 - To resolve the error, here are some methods you can try based on your environment needs: For the most reliable control over Python packages, consider creating a virtual environment or using venv: python -m venv myenv source myenv/bin/activate # On Windows use: myenv\Scripts\activate pip install <package_name> With the virtual environment active, you should be able to install packages freely without interference from external management. This is ideal for project-specific installations or experimenting with different package versions.
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › hardware and peripherals › camera board
pibooth install error, "externally- managed-environment - Raspberry Pi Forums
March 9, 2024 - 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. For more information visit http://rptl.io/venv 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.
🌐
Medium
dushyant37.medium.com › python-error-this-environment-is-externally-managed-e4f65d508b31
Python error — This environment is externally managed | by Dushyant Bansal | Medium
October 2, 2024 - If you wish to install a Python library that isn't in Homebrew, use a virtual environment: python3 -m venv path/to/venv source path/to/venv/bin/activate python3 -m pip install xyz If you wish to install a Python application that isn't in Homebrew, it may be easiest to use 'pipx install xyz', which will manage a virtual environment for you. You can install pipx with brew install pipx You may restore the old behavior of pip by passing the '--break-system-packages' flag to pip, or by adding 'break-system-packages = true' to your pip.conf file. The latter will permanently disable this error.
🌐
MakeUseOf
makeuseof.com › home › linux › how to fix the pip "externally-managed-environment" error on linux
How to Fix the pip "externally-managed-environment" Error on Linux
October 18, 2023 - All you have to do is navigate to /usr/lib/python3.xx and delete the EXTERNALLY-MANAGED file in the directory. Here are the commands to do so: ... That's all you need to do to fix the error.
🌐
Arch Linux Forums
bbs.archlinux.org › viewtopic.php
What's the story on pip's externally-managed-environment error? / System Administration / Arch Linux Forums
$ pip install . error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try 'pacman -S python-xyz', where xyz is the package you are trying to install. If you wish to install a non-Arch-packaged Python package, create a virtual environment using 'python -m venv path/to/venv'.
🌐
Zaber Technologies
zaber.com › articles › python-virtual-environment
Resolving Python "Externally Managed Environment" Errors (MacOS +
June 17, 2024 - This means the OS takes care of Python, not a tool like pip. As a result, using pip install ... on the system Python will now trigger an "externally-managed-environment" error. There are two avenues for resolving this.
🌐
YouTube
youtube.com › watch
How to fix error: externally-managed-environment in Python 3.12 the Wrong Way - YouTube
On Linux:Add the following to /etc/pip.config[global]break-system-packages = trueOn Windows:C:\ProgramData\pip\pip.ini[global]break-system-packages = trueRef
Published   October 12, 2024
🌐
GitHub
github.com › boltgolt › howdy › issues › 858
Ubuntu 23.10, GNOME 45 - PIP - (error: externally-managed-environment) · Issue #858 · boltgolt/howdy
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.
Author   boltgolt