Python is a general-purpose programming language used across web development, data science, machine learning, automation, and system administration. It has clean syntax, a large standard library, and runs on every major platform. Python 3.13 is the default interpreter in Debian 13 (Trixie), so installing it takes a single apt command. For those who need the absolute latest patch release (3.13.12 at the time of writing), building from source is straightforward.
This guide covers two methods to install Python 3.13 on Debian 13 (Trixie) – from the default APT repositories and from source. We also cover setting up virtual environments with venv, using pip to manage packages, and verifying the installation.
Prerequisites
- A server or workstation running Debian 13 (Trixie)
- Root or sudo access
- Internet connectivity to download packages or source tarballs
Method 1: Install Python 3.13 on Debian 13 from APT
Debian 13 Trixie ships Python 3.13 as its default Python 3 interpreter. This is the recommended method for most users.
Step 1: Update system packages
Start by updating the package index and upgrading existing packages.
sudo apt update && sudo apt upgrade -y
Reboot if a kernel update was applied.
[ -f /var/run/reboot-required ] && sudo reboot -f
Step 2: Install Python 3.13
Install the Python 3 interpreter along with the venv module and development headers.
sudo apt install python3 python3-venv python3-dev python3-pip -y
Step 3: Verify the installation
Confirm Python 3.13 is installed and working.
$ python3 --version
Python 3.13.5
Check that pip is available.
$ pip3 --version
pip 24.3.1 from /usr/lib/python3/dist-packages/pip (python 3.13)
Method 2: Install Python 3.13 from Source on Debian 13
Building from source gives you the latest patch release with all security fixes and performance improvements. This is useful when you need a newer version than what Debian ships or want to enable experimental features like the free-threaded build or JIT compiler. If you’re working with Python on Ubuntu as well, the source build process is similar.
Step 1: Install build dependencies
Install the compiler toolchain and all libraries needed for a full-featured Python build.
sudo apt install wget build-essential libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev liblzma-dev -y
Step 2: Download Python source
Download the latest Python 3.13 source tarball from the official Python downloads page.
wget https://www.python.org/ftp/python/3.13.12/Python-3.13.12.tar.xz
Extract the archive.
tar -xvf Python-3.13.12.tar.xz
Step 3: Configure and compile
Change into the source directory and run the configure script with optimizations enabled. The --enable-optimizations flag runs profile-guided optimization (PGO), which makes the final binary noticeably faster.
cd Python-3.13.12
./configure --enable-optimizations
Compile and install using altinstall to avoid overwriting the system Python.
sudo make altinstall
The altinstall target installs the binary as python3.13 instead of python3, keeping the system default intact. This compilation can take 5-15 minutes depending on hardware.
Step 4: Verify the source build
Check that the newly built Python is available.
$ python3.13 --version
Python 3.13.12
The binary is installed to /usr/local/bin/python3.13. If you want to make it the default python3, use update-alternatives.
sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.13 1
Setting Up Python Virtual Environments on Debian
Virtual environments isolate project dependencies so they do not conflict with system packages or other projects. Always use a virtual environment for Python development – never install packages globally with pip on a modern Debian system, as it will be blocked by default (PEP 668).
Step 1: Create a virtual environment
Create a new virtual environment in your project directory.
python3 -m venv ~/myproject/venv
Step 2: Activate the virtual environment
Activate it before installing any packages.
source ~/myproject/venv/bin/activate
Your shell prompt changes to show the active environment name.
$ which python3
/home/user/myproject/venv/bin/python3
Step 3: Install packages inside the venv
With the environment active, use pip to install packages. They are contained entirely within the venv directory. For example, to install a web framework like Flask with Gunicorn for a web project:
pip install flask
Verify the installed package.
$ pip show flask
Name: Flask
Version: 3.1.0
Summary: A simple framework for building complex web applications.
Location: /home/user/myproject/venv/lib/python3.13/site-packages
Requires: blinker, click, itsdangerous, Jinja2, Werkzeug
Step 4: Deactivate the virtual environment
When finished working in the project, deactivate the environment.
deactivate
Using pip to Manage Python Packages
The pip package manager comes bundled with Python 3.13 on Debian 13. Here are the most common operations – always run these inside a virtual environment.
Install a package
pip install package_name
Install a specific version
pip install package_name==2.0.1
Upgrade a package
pip install --upgrade package_name
List installed packages
pip list
Uninstall a package
pip uninstall package_name
Export and reproduce dependencies
Save all current dependencies to a requirements file for reproducible deployments.
pip freeze > requirements.txt
Reinstall from a requirements file on another machine or environment.
pip install -r requirements.txt
Running a Python Script on Debian 13
Test your installation by running the interactive interpreter.
$ python3
Python 3.13.5 (main, Mar 10 2026, 12:15:42) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Python 3.13 includes an improved interactive interpreter with syntax highlighting, multiline editing, and colored output. Try a quick test.
>>> import sys
>>> print(f"Python {sys.version}")
Python 3.13.5 (main, Mar 10 2026, 12:15:42) [GCC 14.2.0]
>>> exit()
To run a script from a file, create a simple test script. If you plan to build larger applications, consider using Django on Debian for web projects.
vi ~/hello.py
Add the following content:
#!/usr/bin/env python3
import platform
print(f"Hello from Python {platform.python_version()}")
print(f"Running on {platform.system()} {platform.release()}")
Run the script.
$ python3 ~/hello.py
Hello from Python 3.13.5
Running on Linux 6.12.27-amd64
Conclusion
Python 3.13 is available out of the box on Debian 13 Trixie through APT, making installation a one-command operation. For the latest patch release, building from source with --enable-optimizations gives you a PGO-optimized binary. The same source build approach works on RHEL, Rocky Linux, and AlmaLinux if you manage mixed environments.
For production deployments, always use virtual environments to isolate dependencies, pin package versions with requirements.txt, and keep Python updated with security patches from Debian’s package manager.