If you are on Windows follow WSL 2 installation guide first.

Add dead snakes PPA, this is a special DEB repository that holds all python versions. Compatible with all Debian bases repositories: Ubuntu, Mint, WSL2 Ubuntu

sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa

Now type the next command to install the main python DEB package of a specific version:

sudo apt install python3.7

Instead of 3.7 use any version you need.

For some specific projects and packages you might also need other DEB packages:

  • python#.#-dev: includes development headers for building C extensions
  • python#.#-venv: provides the standard library venv module
  • python#.#-distutils: provides the standard library distutils module
  • python#.#-lib2to3: provides the 2to3-#.# utility as well as the standard

Image for a hint