---
title: How to Install Python 2 on Debian 12
url: https://docs.vultr.com/how-to-install-python-2-on-debian-12
description: Learn how to install Python 2 on Debian 12 with our step-by-step guide. Follow these instructions to get Python 2 running on your Debian 12 system quickly and easily.
publish_date: 2025-07-02T15:59:08.673586Z
last_updated: 2025-07-02T15:59:08.673586Z
author: Syam Sarosa
header_image: https://docs.vultr.com/public/doc-assets/2246/bd8a8177-10af-4d5f-b829-904ebea9ebf9.png
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

Python 2 was widely used for many years before reaching its end-of-life (EOL) on January 1, 2020. While Python 2 is no longer maintained, some legacy applications still use it.

This article shows how to install Python 2.7.18 and PIP from source on a Debian 12 instance, verify the installation, and run a Python script to confirm that Python 2 works as expected.

> [!WARNING]
> Python 2 is no longer maintained and should not be used for new development. Use it only if a legacy application requires it.

## Prerequisites

Before you begin:

* Have access to a [Debian 12](https://www.vultr.com/docs/introduction-to-debian/) based Linux instance as a non-root sudo user.

## Install Python 2

Debian 12 does not include Python 2 in its default repositories. To install it, compile Python 2.7.18 from source.

1. Update the APT package index.

    ```console
    $ sudo apt update
    ```

1. Upgrade installed packages.

    ```console
    $ sudo apt upgrade -y
    ```

1. Install required dependencies.

    ```console
    $ sudo apt install libreadline-dev libbz2-dev libsqlite3-dev libssl-dev -y
    ```

1. Download the Python 2.7.18 source code.

    ```console
    $ wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
    ```

1. Extract the archive.

    ```console
    $ tar zxf Python-2.7.18.tgz
    ```

1. Switch to the Python source folder.

    ```console
    $ cd Python-2.7.18
    ```

1. Run the `configure` script to set up the build system.

    ```console
    $ ./configure --prefix=/usr/local --enable-optimizations
    ```

    In the command above:

    * `--prefix=/usr/local`: Installs Python in the `/usr/local` directory.
    * `--enable-optimizations`: Enables performance optimizations such as LTO and PGO.

1. Compile the build files.

    ```console
    $ make
    ```

1. Install Python 2 from the built source.

    ```console
    $ sudo make install
    ```

1. Verify the installation.

    ```console
    $ python2 --version
    ```

    Output:

    ```
    Python 2.7.18
    ```

## Install PIP for Python 2

PIP is the package manager for Python. For Python 2, install PIP 2 using the `get-pip.py` script.

1. Download the installation script.

    ```console
    $ curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py
    ```

1. Install PIP 2 using Python 2.

    ```console
    $ python2 get-pip.py
    ```

1. If you see the following warning in your output:

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

    1. Add the directory to your `PATH`.

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

    1. Update your shell environment's PATH variable.

        ```console
        $ source ~/.bashrc
        ```

1. Verify the installation.

    ```console
    $ pip2 --version
    ```

    Example output:

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

## Test and Use Python 2 and PIP

To test your Python 2 installation, follow the steps below.

1. Create a Python script for testing purposes.

    ```console
    $ nano hello.py
    ```

1. Add the following contents to the file:

    ```python
    print "Hello from Python 2"
    ```

    Save and exit the file.

1. Run the script.

    ```console
    $ python2 hello.py
    ```

    Output:

    ```
    Hello from Python 2
    ```

    This validates your Python 2 installation.

1. Try installing a PIP package, such as the `lxml` package.

    ```console
    $ pip2 install lxml
    ```

    If the command works and installs the package, your PIP 2 is working.

## Conclusion

In this article, you installed Python 2.7.18 and PIP 2 on a Debian 12 instance from the source and tested them. This setup enables legacy Python 2 applications to run on modern systems. Avoid using Python 2 for new development and migrate to Python 3 to ensure continued support and security.
