I am not sure why this happens but each time i install a new linux system and i try to pip install a python library i am getting the following warning/error message:
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.
So if you are having the same problem, here is how to fix it:
First of all make sure you have Pip installed for your linux. Here i'll go with Ubuntu, you can change the command line according to your Linux system:
$ sudo apt update
$ sudo apt install python3-pip
Now check to verify the installation of Pip:
pip3 –version
You're ready to fix the problem for installing modules/librarires for Python. Type the following to your terminal:
$ python3 -m pip config set global.break-system-packages true
You can now install pip packages however use it carefully as there is always a chance to break your linux system!
Top comments (1)
I use poetry with pyenv.
Poetry for managing virtual environment and packages version and pyenv for managing python version, and it works like a charm.
Everyone should try it. Also, it's not recommended to install python packages systemwide like this. It's better to make a python virtual environment for the project.