Tutorials  /  Python

Install Python 2.7.18 & PIP on Debian 12 from Source

Ccentron Redaktion · August 2025 ·4 min read ·Python, Tutorial

Python 2 was a popular choice for many years until it reached end-of-life (EOL) on January 1, 2020. While it is no longer maintained, some legacy software still depends on it.

This guide explains how to compile and install Python 2.7.18 and PIP on a Debian 12 system, verify the setup, and run a test script to confirm everything works as expected.

Important Notice

Python 2 is no longer supported. Avoid using it for new projects—only use it when maintaining or running legacy applications that explicitly require it.

VM

Matching infrastructure at centron

Scripts and services eventually need an environment that keeps running: ccloud³ VMs from €3.12 per month, billed by the hour. Rent a cloud server →

Prerequisites

  • Access to a Debian 12 Linux instance
  • A non-root user account with sudo privileges

Step 1 – Installing Python 2

Since Debian 12 no longer includes Python 2 in its repositories, you need to compile Python 2.7.18 from source.

Update the package index

Console
sudo apt update

Upgrade installed packages

Console
sudo apt upgrade -y

Install required build dependencies

Console
sudo apt install libreadline-dev libbz2-dev libsqlite3-dev libssl-dev -y

Download Python 2.7.18 source

Console
wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz

Extract the archive

Code
tar zxf Python-2.7.18.tgz

Navigate to the source directory

Console
cd Python-2.7.18

Configure the build

This sets up the compilation environment.

Code
./configure --prefix=/usr/local --enable-optimizations
  • --prefix=/usr/local: Installs Python into the /usr/local directory.
  • --enable-optimizations: Enables performance features such as LTO and PGO.

Compile the source

Code
make

Install Python 2

Console
sudo make install

Verify installation

Code
python2 --version

Expected output:

Python 2.7.18

Step 2 – Installing PIP for Python 2

PIP is Python’s package installer. For Python 2, you can install it using the get-pip.py script.

Download the installer script

Console
curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py

Run the installer

Code
python2 get-pip.py

If you see a warning like:

WARNING: The scripts pip, pip2, and pip2.7 are installed in '/home/your-user/.local/bin', which is not on PATH.

Add the directory to PATH

Console
echo 'export PATH=$PATH:$HOME/.local/bin' >> ~/.bashrc

Reload shell configuration

Code
source ~/.bashrc

Check PIP version

Code
pip2 --version

Example output:

pip 20.3.4 from /home/your-user/.local/lib/python2.7/site-packages/pip (python 2.7)

Step 3 – Testing Python 2 and PIP

To verify that Python 2 works properly, create a simple script.

Create a test script

Code
nano hello.py

Insert this code into the file:

Code
print "Hello from Python 2"

Run the script

Code
python2 hello.py

Expected output:

Hello from Python 2

Test installing a package

Code
pip2 install lxml

If the installation succeeds, PIP is functioning correctly.

Conclusion

In this guide, you compiled and installed Python 2.7.18 along with PIP 2 on Debian 12 from source, then tested them to ensure proper functionality. This setup allows legacy Python 2 applications to run on modern systems. For all new development, use Python 3 to ensure continued updates, security patches, and support.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Python
Teilen
Noch offene Fragen?

Unser Team hilft Ihnen bei Ihrem konkreten Setup weiter – von Menschen, die die Plattform selbst betreiben.

War dieses Tutorial hilfreich?

Ihre Antwort wird anonym gespeichert und hilft uns, die Tutorials zu verbessern.

Kommentare

Noch keine Kommentare – stellen Sie die erste Frage zu diesem Tutorial.

Zum Kommentieren anmelden

Kommentare stehen centron-Kunden offen. Melden Sie sich in Ihrem Konto an, um eine Frage zu diesem Tutorial zu stellen.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren