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
767

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.

🌐
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/>
Discussions

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
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
error: externally-managed-environment
Crash & Error krishna@torque:~$ python3 -m pip install pip error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try apt ... More on github.com
🌐 github.com
37
February 22, 2023
On MacOS 14, pip install throws error: externally-managed-environment
On MacOS 14, pip install throws error: externally-managed-environment. What’s the best way to resolve? My background and exploration so far. I’m a recently retired devops engineer. Mostly used bash and DSLs on the job plus dabbled in Python, Ruby, Go. Now wanting to really learn Python. More on discuss.python.org
🌐 discuss.python.org
5
1
April 5, 2024
🌐
Built In
builtin.com › articles › error-externally-managed-environment
How to Fix “error: externally-managed-environment” in Pip | Built In
2 weeks ago - 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 ...
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 › help › knowledge base › semgrep appsec platform › error: externally-managed-environment
error: externally-managed-environment | Semgrep
2 weeks ago - 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
... 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 ...
🌐
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 ...
Find elsewhere
🌐
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'.
🌐
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.
🌐
GitHub
github.com › python › cpython › issues › 102134
error: externally-managed-environment · Issue #102134 · python/cpython
February 22, 2023 - krishna@torque:~$ python3 -m pip install pip 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.
Author   krishnaTORQUE
🌐
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 ...
🌐
Linux Mint Forums
forums.linuxmint.com › board index › main edition support › software & applications
How to fix pip3 install or pip install "externally managed" problem in Linux Mint 22 - Linux Mint Forums
September 16, 2024 - Another solution is to install and run your packages in a virtual environment. Instructions- 1. Open up terminal 2. Create a new environment python -m venv ~/myenv 3. Activate the environment source ~/myenv/bin/activate 4. Install your python program. I am using the python program "streamlink" ...
🌐
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.
🌐
Python.org
discuss.python.org › python help
On MacOS 14, pip install throws error: externally-managed-environment - Python Help - Discussions on Python.org
April 5, 2024 - On MacOS 14, pip install throws error: externally-managed-environment. What’s the best way to resolve? My background and exploration so far. I’m a recently retired devops engineer. Mostly used bash and DSLs on the job …
🌐
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   ghost
🌐
Mac Install Guide
mac.install.guide › python › externally-managed-environment
Fix error: externally-managed-environment on Mac · 4 Ways · 2026
2 weeks ago - 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).
🌐
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.
🌐
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