我正在尝试在 Ubuntu v20.04 Docker 映像上安装 Python3.10。我正在使用这条线:
FROM nrel/energyplus:23.2.0
RUN export DEBIAN_FRONTEND=noninteractive TZ=US && \
apt-get update && \
apt-get -y install python3.10 python3-pip
似乎运行正常,并且我得到了成功的图像。
但是当我运行容器时,我似乎只安装了Python3.8?
# python3 --version
Python 3.8.10
# python3.10 --version
/bin/sh: 3: python3.10: not found
# whereis python3
python3: /usr/bin/python3.8 /usr/bin/python3 /usr/bin/python3.8-config /usr/lib/python3 /usr/lib/python3.8 /usr/lib/python3.9 /etc/python3.8 /etc/python3 /usr/local/lib/python3.8 /usr/include/python3.8 /usr/share/python3
这种情况下如何安装Python 3.10?
尝试安装
apt-get
时,请仔细查看 python3.10
的输出:
root@3d5f9653d655:/# apt-get -y install python3.10
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libqgispython3.10.4' for regex 'python3.10'
Note, selecting 'libpython3.10-stdlib' for regex 'python3.10'
libqgispython3.10.4 is already the newest version (3.10.4+dfsg-1ubuntu2).
0 upgraded, 0 newly installed, 0 to remove and 23 not upgraded.
它将
python3.10
视为正则表达式,并将其与 libqgispython3.10.4
进行匹配。没有可用的 python3.10
软件包,如果您使用 apt
命令而不是 apt-get
,您会收到更好的错误消息:
root@3d5f9653d655:/# apt install python3.10
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3.10
E: Couldn't find any package by glob 'python3.10'
此行为记录在
apt-get
手册页中:
如果没有包与给定表达式匹配并且该表达式包含以下之一
、.
或?
那么它被假定为 POSIX 正则表达式,并且它是 适用于数据库中的所有包名称。然后安装任何匹配项 (或删除)。请注意,匹配是通过子字符串完成的,因此*
匹配lo.*
和how-lo
。如果不希望出现这种情况,请将正则表达式锚定为lowest
或^
字符,或创建更具体的正则表达式。$
这是一种愚蠢的行为,特别是因为包名称合法地包含
.
字符,但我们显然坚持这样做。