I am attempting to install Python3.10 on a Ubuntu v20.04 Docker Image. I am using the line:
FROM nrel/energyplus:23.2.0
RUN export DEBIAN_FRONTEND=noninteractive TZ=US && \
apt-get update && \
apt-get -y install python3.10 python3-pip
which seems to run properly, and I get a successful Image.
However when I run the Container, I appear to only have Python3.8 installed?
# 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
How can I install Python 3.10 in this case?
>Solution :
Take a closer look at the output from apt-get when you attempt to install 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.
It treats python3.10 like a regular expression, and matches it against libqgispython3.10.4. There is no python3.10 package available, and if you were to use the apt command instead of apt-get you would get a better error message:
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'
This behavior is documented in the apt-get man page:
If no package matches the given expression and the expression contains one of
.,?or*then it is assumed to be a POSIX regular expression, and it is
applied to all package names in the database. Any matches are then installed
(or removed). Note that matching is done by substring solo.*matches
how-loandlowest. If this is undesired, anchor the regular expression with
a^or$character, or create a more specific regular expression.
It’s a dumb behavior, particularly because packages name legitimately contain . characters, but we’re apparently stuck with it.