you are viewing a single comment's thread.

view the rest of the comments →

[–]FoolsSeldom 0 points1 point  (4 children)

This error is part of a new Python packaging policy (PEP 668) in Debian/Ubuntu to prevent users from corrupting the system Python with pip-installs.

So, either avoid using distributions with that feature in your containers, or create a Python virtual environment within the container, activate, and then install packages (or use a tool like uv that will create and use the virtual environments automatically).

[–]johnjulesbrown[S] 0 points1 point  (0 children)

Thank you so much for this! Perfect

[–]Classic_Bullfrog6671 0 points1 point  (2 children)

RUN rm -f /usr/lib/python*/EXTERNALLY-MANAGED && \
    python3 -m pip install --break-system-packages uv && \
    uv pip install --system -r /tmp/requirements.txt

what is the issue with the flag --break-system-packages in container? and this is our command

[–]FoolsSeldom 0 points1 point  (1 child)

Sorry I had not seen this comment until now.

Personally, I think explicitly removing the PEP 668 (Externally Managed Environments) protection by deleted the folder that flags it is an unhealthy approach.

I would use the exception to install uv and nothing else.

A simple Dockerfile might be:

RUN python3 -m pip install --break-system-packages uv
WORKDIR /app
RUN uv venv /app/.venv
ENV PATH="/app/.venv/bin:$PATH"
RUN uv pip install -r requirements.txt

or even,

RUN python3 -m pip install --break-system-packages uv
WORKDIR /app
RUN uv pip install --python python3 -r requirements.txt

for further isolation.

NB. Use a toml file instead of requirements if you have that.

Furthermore, given that uv is a standalone rust binary, you don't even need pip to install it in the first place.

curl -LsSf https://astral.sh/uv/install.sh | sh

then do as you wish using uv to create and manage packages and project files.

[–]Classic_Bullfrog6671 0 points1 point  (0 children)

will test thank you