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 (2)
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.
what your doing is totally goes out of the linux package manager philosophy! More like it might break your system packages or updates.
create a venv if you need or just install the package using your package manager such as apt or pacman,
why-:
suppose one of your package uses python-xyx version1.23 in a package to build for a specific package package-var
now u did pip install python-xyx --break-system-packages
what might happen: pip changes the system package installed package
-> its all and good if version are not changed or no version compatibility issues with the package-var
-> but if that happens then package-var breaks, when you try to update your system your package-manager couldn't find the python-xyx package with actual version linked with the installed-list, your update breaks, your package-manager panics , sometime many related packages also breaks all together.
Imagine it being like 2 person working on the main branch with push --force flag. one overwrites someones work and things are all messy and needs a manual fix or kind of redo a whole part