How do I fix pip error - "this environment is externally managed"?

After upgrading my Debian-based system, I now get the error “this environment is externally managed” every time I run pip install xyz.

The error suggests using apt install, creating a virtual environment, or installing with pipx. This didn’t happen before the upgrade, pip install worked fine.

Why is pip suddenly restricted this way, and what’s the safe, recommended way to install packages now?

Also, what are the risks of bypassing this error with --break-system-packages, and when (if ever) is it okay to use that?

One of the cleanest ways around this error is to avoid touching the system Python altogether. Just create a virtual environment using:

python3 -m venv myenv
source myenv/bin/activate

Once you’re inside the venv, pip behaves exactly like before, no restrictions, no warnings. This keeps your global system packages safe, and you can install or upgrade whatever you want inside the isolated environment.

It’s especially useful if you’re juggling different project dependencies.