Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install Python on Debian

Install Python 3 from the Debian repository, with Snap, or compile a newer version from source.

VPS and Cloud Servers2 min read3 steps12 screenshots

Method 1: The Debian repository

sudo apt install python3
Installing Python 3 with apt

Check the version:

python3 --version
The Python version

(On Debian the python command may not exist. Use python3, or install the package python-is-python3.)

Also install pip and the venv module if you need them:

sudo apt install python3-pip python3-venv

Method 2: Snap

Search for Python packages:

snap find python
Searching for Python in Snap

Install one (a version-named package, if it is offered):

sudo snap install python38
Installing Python with Snap

Snap needs snapd (sudo apt install snapd).

Method 3: Compile from source

Use this to get the newest version.

Step 1: Install the build tools

sudo apt install build-essential libssl-dev libsqlite3-dev libbz2-dev libgdbm-dev libncurses5-dev libncursesw5-dev libreadline-dev zlib1g-dev libffi-dev wget
Installing the dependencies

Step 2: Download the source

wget https://www.python.org/ftp/python/3.12.2/Python-3.12.2.tgz
Downloading Python

Step 3: Extract it and go into the folder

tar xzf Python-3.12.2.tgz
cd Python-3.12.2
Extracting the archive

Step 4: Configure

./configure --enable-optimizations
Configuring Python

Step 5: Install make (if it is missing)

sudo apt install make
Installing make

Step 6: Build

make -j $(nproc)
Compiling Python

Step 7: Install

sudo make altinstall
Installing Python

altinstall leaves the system Python as it is, and installs the new one as python3.12.

Step 8: Check it

python3.12 --version
The new Python version

Why install Python on Debian

  1. Compatibility and stability. Debian is a stable base for Python apps.
  2. Package management. apt and pip handle your software.
  3. A big community. There is a lot of help for both.

Quick recap

  • sudo apt install python3 is the simple way.
  • Compile from source for a newer version, with altinstall.
  • Use python3 -m venv for your projects.