Python libraries installation and the "this environment is externally managed."

March 14, 2024, 11:38

oops.se

The reason for the error message "this environment is externally managed." is that you can install python libraries only from the package library (apt). One way is with Debian's packages manager "apt" and the other way is with Pythons installer "pip" and this can cause conflicts. To solve this has the Python foundation written an Python Enhancement Proposals [PEP 668 – Marking Python base environments as “externally managed”](https://peps.python.org/pep-0668/) So you have 4 options: 1. Use apt as is recommended, but if the package/library isn't available in apt... 2. Use venv, check [stack overflow](https://stackoverflow.com/questions/75602063/pip-install-r-requirements-txt-is-failing-this-environment-is-externally-mana/75696359#75696359) for an guide how to implement a virtual environment. 3. Use pip's argument --break-system-packages, this is NOT recommended! 4. Disable the "externally-managed-environment" feature and you guessed correct this is also NOT recommended. sudo rm /usr/lib/python3.11/EXTERNALLY-MANAGED Resources: [PEP 668 – Marking Python base environments as “externally managed”](https://peps.python.org/pep-0668/) https://docs.python.org/3/library/venv.html [pip install -r requirements.txt is failing: "This environment is externally managed"](https://stackoverflow.com/questions/75602063/pip-install-r-requirements-txt-is-failing-this-environment-is-externally-mana/75696359#75696359)