“Externally managed environments”: when PEP 668 breaks pip

You’re on a new version of Linux, you try a pip install, and it errors out, talking about “externally managed environments” and “PEP 668”.
What’s going on?
How do you solve this?

Let’s see:

  • What the problem looks like, and what causes it.
  • The places you are likely to encounter it.
  • A variety of solutions, depending on your use case.

Symptoms: failed installs

Consider the following Dockerfile, using a pre-release of Debian “Bookworm” 12, which will be released in June 2023:

FROM debian:bookworm
RUN apt-get update && apt-get -y install python3 python3-pip
RUN pip install flask

This seems pretty straightforward, similar to many Docker examples you’ll find.
And yet when

 

 

 

To finish reading, please visit source site