How to solve error: externally-managed-environment PIP error on Ubuntu ?
If you are running Ubuntu 23.04 or later and try to run ‘pip install’ commend, then you will get this “error: externally-managed-environment“. Because you can not run pip install command outside a virtual environment to avoid conflicts between APT and Python package manager PIP.
Fix Pip Install externally-managed-environment Error
Method 1: Use PIPX Install
Using pipx, you can easily Install and Run Python applications in Isolated Environments. In the terminal app (ctrl+alt+t) run below pipx install command.
sudo apt install pipx
and add it your PATH
Now install any python app by replace pip to pipx like below
pipx install netpaint
sudo pipx install netpaint
Here “netpaint” is the python app package name. You can replace it with your app name.
Method 2: Create a virtual environment using venv or virtualenv
First install venv using below command.
sudo apt install python3-venv
Then create a new virtual environment in a directory named env using below command.
python3 -m venv env
To activate this virtual environment, run below command.
Now you can install the python package via pip like this. The files will get installed under the env/ directory.
pip install netpaint
pip3 install netpaint
Method 3: Ignore the warning
You can also ignore the warning using the –break-system-packages flag in your pip install command. Like below command.
pip install --break-system-packages --user netpaint