
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.
Python 2 is no longer maintained and should not be used for new development. Use it only if a legacy application requires it.
Before you begin:
Debian 12 does not include Python 2 in its default repositories. To install it, compile Python 2.7.18 from source.
Update the APT package index.
Upgrade installed packages.
Install required dependencies.
Download the Python 2.7.18 source code.
Extract the archive.
Switch to the Python source folder.
Run the configure script to set up the build system.
In the command above:
--prefix=/usr/local: Installs Python in the /usr/local directory.--enable-optimizations: Enables performance optimizations such as LTO and PGO.Compile the build files.
Install Python 2 from the built source.
Verify the installation.
Output:
PIP is the package manager for Python. For Python 2, install PIP 2 using the get-pip.py script.
Download the installation script.
Install PIP 2 using Python 2.
If you see the following warning in your output:
Add the directory to your PATH.
Update your shell environment's PATH variable.
Verify the installation.
Example output:
To test your Python 2 installation, follow the steps below.
Create a Python script for testing purposes.
Add the following contents to the file:
Save and exit the file.
Run the script.
Output:
This validates your Python 2 installation.
Try installing a PIP package, such as the lxml package.
If the command works and installs the package, your PIP 2 is working.
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.
0 Comments
Be the first to comment and share your perspective with the community.