Installing a project's dependencies into the system Python
Commonpip install -r requirements.txt, run with the system python3 on Debian 12+, Ubuntu 24.04+ or Homebrew, targets the managed environment and is refused.
Confirm
python3 -c 'import sys,sysconfig,os; print(sys.prefix == sys.base_prefix, os.path.exists(os.path.join(sysconfig.get_path("stdlib"), "EXTERNALLY-MANAGED")))'True True: not in a venv, and the Python is marked
Fix
- Create a virtual environment for the project and install into it:
python3 -m venv .venv, then.venv/bin/pip install -r requirements.txt, and run the project with.venv/bin/python. - On Debian or Ubuntu, if venv is missing, install it first:
sudo apt install python3-venv(orpython3-full).
python3 -m venv .venv && .venv/bin/pip install -r requirements.txt
Activate with source .venv/bin/activate if you prefer plain python and pip afterwards.