ipython 版本与 docker 中的 python 版本不匹配

ipython version mismatches python version in docker

我正在使用以下 Dockerfile 构建一个 docker:

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

当我运行图像的时候我很惊讶地看到ipython的版本是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)

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

至少有三个选项。

使用 python 基础图像

官方 python 基础映像包括 pip。如果可能的话,我会使用其中之一。

  • python:3.8 - 包括用于安装已编译包的编译器
  • python:3.8-slim - 不包括编译器

使用 get-pip.py 脚本安装 pip

可以在没有系统包管理器的情况下安装 pip,例如使用脚本 get-pip.py:

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

使用ubuntu20.04

一样,ubuntu20.04默认使用3.8python。但是,与使用官方 python docker 图像之一相比,您对 python 版本的细粒度控制较少。