To install python from source (on my current 21.04) ubuntu distro execute next commands:
Current version: 3.10.4
Note: when install fails on xxxx, install specific setuptools and restart the install (will probalbly only happen on upgrading):
python<current> -m pip install setuptools@git+https://github.com/pypa/setuptools.git@v60.5.4
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev libncurses-dev libgdbm-dev libz-dev tk-dev libsqlite3-dev libreadline-dev liblzma-dev libffi-dev libgdbm-compat-dev
wget https://www.python.org/ftp/python/3.10.<x>/Python-3.10.<x>.tgz
tar -xf Python-3.10.<x>.tgz
cd Python-3.10.<x>
./configure --enable-optimizations
make -j <nr of cores>
sudo make altinstall