Home > Enterprise >  ipython version mismatches python version in docker
ipython version mismatches python version in docker

Time:12-01

I'm building a docker with the following Dockerfile:

FROM ubuntu:18.04
RUN                               \
apt-get update -y              && \
apt-get install python3.8 -y   && \ <----- I ask for python3.8
apt-get install python3-pip -y && \
pip3 install ipython

When I ran the image I was surprised to see that the version of ipython is 3.6.9:

$ docker build --tag versions --file .\Dockerfile.txt .
$ docker run -d -t --name ver versions
ba9bd772bc6d247a6c83f2bf932a6c5172c23f00e1e6a35f14878608d0f35f89
$ docker exec -it ver bash
# ipython
Python 3.6.9 (default, Jan 26 2021, 15:33:00)

CodePudding user response:

The package python3-pip depends on python3, and the default python3 for ubuntu 18.04 is version 3.6.

There are at least three options.

Use a python base image

The official python base images include pip. If possible, I would use one of these.

  • python:3.8 - includes compilers to install compiled packages
  • python:3.8-slim - does not include compilers

Install pip with the get-pip.py script

One can install pip without the system package manager, for example with the script get-pip.py:

wget https://bootstrap.pypa.io/get-pip.py
python3.8 get-pip.py

Use ubuntu 20.04

As @NickODell comments, ubuntu 20.04 uses 3.8 as the default python. But you will have less fine-grained control over the python version than if you use one of the official python docker images.

  • Related