python-3.xdocker

Setting specific python version in docker file with specfic non-python base image


I want to create a docker image with specifically python 3.5 on a specific base image which is the nvidia/cuda (9.0-base image) the latter has no python environment.

The reason I need specific versions is to support running cuda10.0 python3.5 and a gcc version<7 to compile the driver all together on the same box

When I try and build the docker environments (see below) I always end up with the system update files which load python3.6

The first version I run (below) runs a system update dependencies which installs python 3.6 I have tried many variants to avoid this but always end up 3.6 in the final image.

Any suggestions for getting this running with python3.5 are welcome

Thanks

FROM nvidia/cuda

RUN apt-get update && apt-get install -y libsm6 libxext6 libxrender-dev python3.5 python3-pip 

COPY . /app
WORKDIR /app

RUN pip3 install -r requirements.txt
ENTRYPOINT [ "python3" ]
CMD [ "app.py" ]

Another variant (below) I have tried is with virtualenv and here again I can't seem to force a python 3.5 environment

FROM nvidia/cuda

RUN apt-get update && apt-get install -y --no-install-recommends libsm6 libxext6 libxrender-dev python3.5 python3-pip python3-virtualenv

ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m virtualenv --python=/usr/bin/python3 $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

COPY . /app
WORKDIR /app

RUN pip3 install -r requirements.txt
ENTRYPOINT [ "python3" ]
CMD [ "app.py" ]

Solution

  • You can install from PPA and use it as usual:

    FROM nvidia/cuda
    
    RUN apt-get update && apt-get install -y --no-install-recommends software-properties-common \
        libsm6 libxext6 libxrender-dev curl \
        && rm -rf /var/lib/apt/lists/*
    
    RUN echo "**** Installing Python ****" && \
        add-apt-repository ppa:deadsnakes/ppa &&  \
        apt-get install -y build-essential python3.5 python3.5-dev python3-pip && \
        curl -O https://bootstrap.pypa.io/get-pip.py && \
        python3.5 get-pip.py && \
        rm -rf /var/lib/apt/lists/*
    
    COPY requirements.txt requirements.txt
    
    RUN pip3.5 install -r requirements.txt
    
    CMD ["python3.5", "app.py"]