I am having troubles building docker from ubuntu:24.04, Python version 3.12.3 and pip 25.1.1. Since the recent (I think) defualt pip behavior throwing
error: externally-managed-environment
when calling system-python/pip to install packages, i tried to manage python packages with venv also inside docker.
Then as I usually do i run the container (now with with the /opt/venv) via singularity as non-sudo, providing the target home (e.g., singularity shell -H /home/davide/test docker://myImage)
But now, trying to install additional packages the /opt/venv/bin/pip do not fall-back on local installation in /home/davide/test/.local (as it used to) when /opt/ is found not-writable and fails as follows
pip3 install scanpy
ERROR: Will not install to the user site because it will lack sys.path precedence to numpy in /opt/venv/lib/python3.12/site-packages
here the minimal dockerfile to reproduce the problem
FROM ubuntu:24.04
# general environmental variables
ENV DEBIAN_FRONTEND=noninteractive
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
WORKDIR /
RUN apt-get update -y && apt-get install -y python3 python3-venv python-is-python3 python3-pip
COPY config/requirements.txt /opt/requirements.txt
RUN python3 -m venv --system-site-packages /opt/venv && \
/opt/venv/bin/pip install --no-cache-dir --upgrade pip setuptools && \
/opt/venv/bin/pip install --no-cache-dir -r /opt/requirements.txt
ENV PATH=/opt/venv/bin:${PATH}
ENV PIP_USER=yes
ENTRYPOINT []
with requiirements.txt only having scipy
Some info from the container launched via singularity:
Singularity> python -m site
sys.path = [
'/home/davide/test',
'/usr/lib/python312.zip',
'/usr/lib/python3.12',
'/usr/lib/python3.12/lib-dynload',
'/opt/venv/lib/python3.12/site-packages',
'/usr/local/lib/python3.12/dist-packages',
'/usr/lib/python3/dist-packages',
]
USER_BASE: '/home/davide/test/.local' (doesn't exist)
USER_SITE: '/home/davide/test/.local/lib/python3.12/site-packages' (doesn't exist)
ENABLE_USER_SITE: True
Singularity> which python
/opt/venv/bin/python
Singularity> ls -ltr /opt/venv/bin/
total 17
lrwxrwxrwx 1 root root 7 Jul 30 16:53 python3.12 -> python3
lrwxrwxrwx 1 root root 16 Jul 30 16:53 python3 -> /usr/bin/python3
lrwxrwxrwx 1 root root 7 Jul 30 16:53 python -> python3
-rw-r--r-- 1 root root 2180 Jul 30 16:53 activate.fish
-rw-r--r-- 1 root root 905 Jul 30 16:53 activate.csh
-rw-r--r-- 1 root root 2006 Jul 30 16:53 activate
-rw-r--r-- 1 root root 9033 Jul 30 16:53 Activate.ps1
-rwxr-xr-x 1 root root 226 Jul 30 16:53 pip3.12
-rwxr-xr-x 1 root root 226 Jul 30 16:53 pip3
-rwxr-xr-x 1 root root 226 Jul 30 16:53 pip
-rwxr-xr-x 1 root root 221 Jul 30 16:53 numpy-config
-rwxr-xr-x 1 root root 221 Jul 30 16:53 f2py
I might be missing something basic, but I’m struggling to figure this out. Thanks in advance for any help! :)