Docker change default python version

Hi ,
I have built a docker image using ubuntu.
It installs python 3.5.2

But when I open the interactive container using /bin/bash and re-check the python version.

I have observed that it is set to default python version
/usr/bin/python =>2.7.12
I would like to know, how can I set it to python 3.5.2 using the Dockerfile.

Cheers

Hi @iaarya

Can you please give more details, on how you installed python 3.5.2 and it would be great if you can share the Dockerfile so that we will be able to help you better.

Regards

Hi,
The docker file is as such,

`FROM ubuntu
MAINTAINER xxxx

#set locale
RUN locale-gen en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US.UTF-8
ENV PERL_UNICODE "AS"
ENV LANG C.UTF-8

RUN apt-get -qq update
RUN apt-get -qqy install python3 git ipython screen htop vim octave cmake cmake-curses-gui build-essential g++
cmake cmake-curses-gui bison flex freeglut3 freeglut3-dev libxi6 libxi-dev libxmu6 libxmu-dev libxmu-headers
python3-pip python3-dev python3-scipy python3-numpy python3-lxml imagemagick zlib1g-dev

RUN mkdir -p /opt
WORKDIR /opt
RUN make
RUN make install

WORKDIR /opt/nipype

RUN pip3 install -U pip
RUN pip3 install networkx
RUN pip3 install traits
RUN pip3 install nose
RUN pip3 install future
RUN pip3 install simplejson
RUN pip3 install prov
RUN python3 setup.py install

ENV PYTHONPATH /opt/volgenmodel-nipype
ENV PATH /opt/volgenmodel-nipype/extra-scripts:$PATH

ENV PERL5LIB /usr/local/perl

ADD go.py /opt/
ADD go.sh /opt/

WORKDIR /opt

CMD /bin/bash`

When I look into the container, I observe the path /usr/bin/python is set to default python 2.7.12
But i want it to be set at the new installed python 3.5.2
Can I do this using the dockerfile?

Cheers

The Python 3 command is python3, as used in your Dockerfile. That’s normal. python usually points to Python 2, when outside of a virtualenv.

Hi,

How can I then make python point to Python 3.5 when outside of virtual env.

I do want to do this using the docker file. Currently I am exclusively setting it to 3.5 by entering the container using /bin/bash.

I want the docker image set it to 3.5 and run the code.

Cheers

Something like this ought to do it.

RUN rm -f /usr/bin/python && ln -s /usr/bin/python /usr/bin/python3

However, depending on your platform this may have adverse side effects. For instance, on Redhat family systems, yum is written in Python 2, so swapping python for Python 3 may cause it to stop working. In your Dockerfile, don’t make this change until you are done using other things such as yum which might depend on Python 2.