If you are on Ubuntu 19.10 (Eoan Ermine) (or any other version unsupported by the deadsnakes PPA), you will not be able to install using the deadsnakes PPA.
What you can do instead, is get the source from Python's official website, and install it manually, as described here.
To do so, first, install the dependencies required to build the Python package.
sudo apt install build-essential zlib1g-dev \
libncurses5-dev libgdbm-dev libnss3-dev \
libssl-dev libreadline-dev libffi-dev curl software-properties-common
Then download the tarball and extract it:
wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tar.xz
tar -xf Python-3.9.0.tar.xz
Then cd to the extracted directory:
cd Python-3.9.0
Now configure the script:
./configure
Now, to install Python 3.9 alongside your current Python installation (if any), use:
sudo make altinstall
Lastly, you can verify your installation using
python3.9 --version
How to make python3.X default of Python 3? (Optional)
rm /usr/bin/python3
ln -s /usr/bin/python3.5 /usr/bin/python3
- create an alias in ~/.bash_aliases, ~/.zshrc, etc.
alias python3='/usr/bin/python3.9'
or
alias python3='/usr/local/bin/python3.9'