sudo apt install build-essential checkinstall libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libreadline-dev libffi-dev python3-pip python3-venv liblzma-devFirst, download and extract the desired version of Python 3 as a tarball and extract the tarball. Change into the extracted source directory and run:
sudo ./configure --enable-optimizations
sudo make altinstall