Summary
Python3.9 is available as package distribution for ubuntu, however it can often be a challenge to install it interactively on Ubunt Docker image. This is because Timezone data (tzdata) is not installed and it prompts for Timezone information.
Installing Python3.9 and Pip Nomal
apt update ; apt install -y python3.9 python3-pip
Installing Python 3.9 with TimeZone non-interactively
Installing Python 3.9 with TimeZone non-interactively
apt update
#Setup Timezone package. Not installed by default on Ubuntu, and will cause prompt when trying to install python 3.9
echo "Europe/London" > /etc/timezone
ln -fs /usr/share/zoneinfo/Europe/London /etc/localtime
apt install -y tzdata
#Install required version of Python. installed in /usr/bin
apt install -y python3.9 python3-pip
#Pip3 creates a link called python3 in /usr/bin This link determines which Python3 it works with. So repoint it to version required.
[[ -f /usr/bin/python3 ]] && rm -f /usr/bin/python3
#Linking python3 to python3.9
ln -s /usr/bin/python3.9 /usr/bin/python3