STEP 1. Update.
sudo apt update && sudo apt upgrade
SETP 2. Install below packages on your system, which is required for the installation of Python 3.9 from source code.
sudo apt install wget build-essential libreadline-gplv2-dev libncursesw5-dev \
libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
SETP 3. Download the Python 3.9 source code archive from its official website.
wget https://www.python.org/ftp/python/3.9.7/Python-3.9.7.tgz
SETP 4. Install
tar xzf Python-3.9.7.tgz
cd Python-3.9.7
./configure
make & make install
SETP 5. Change python3 command
rm /usr/bin/python3
ln -s /usr/local/bin/python3.9 /usr/bin/python3
正文完