logo

How to Solve the Error: externally-managed-environment When Installing Python Packages 📂Programing

How to Solve the Error: externally-managed-environment When Installing Python Packages

Issue

error: externally-managed-environment is an error that mainly occurs in Python environments installed by the system package manager on Linux-based systems. It happens because installation of packages from external sources is restricted for security reasons.

Solution

sudo rm /usr/lib/python3.11/EXTERNALLY-MANAGED

If the installed Python version is 3.11, you can remove the EXTERNALLY-MANAGED file as shown above.

Alternative

python3 -m venv proj
source proj/bin/activate

However, in any case this error is raised for security reasons. If you judge deleting the file to be risky, consider creating a virtual environment as shown above and installing packages inside it. A virtual environment is isolated from the system environment, allowing you to install and use packages without affecting the system.

While the virtual environment is activated, you can install packages with pip install, and to use that Python binary you must specify its exact path.