Python 3.8, now considered a historical release, was a significant milestone in Python’s development journey. If you’re operating on Debian-based systems like Debian 12 Bookworm, Debian 11 Bullseye, or Debian 10 Buster, installing Python 3.8 can still offer a stable and feature-rich environment for various applications.
Key Features of Python 3.8
- Assignment Expressions: Introduced the walrus operator
:=, which allows for variable assignments within expressions.
- Positional-only Parameters: Added the
/syntax to specify that certain function parameters must be positional.
- Enhanced F-strings: Allowed for self-documenting expressions and easier debugging with the
- Shared Memory for Multiprocessing: Enabled more efficient data sharing between processes.
__import__(): Optimized the module importing process for quicker performance.
Python’s Evolutionary Context
- Python 1.x: The original series that established Python as a general-purpose language.
- Python 2.x: Introduced in 2000, it brought significant features like garbage collection and Unicode support.
- Python 3.x: Started in 2008, this series has seen consistent performance improvements and feature additions, including those in Python 3.8, 3.9, 3.10, and the current stable release, Python 3.11.
Given Python’s rapid development, with Python 3.11 as the current stable release and Python 3.12 in development, Python 3.8 serves as a stable, though older, option. The following guide will outline the steps to install Python 3.8 on Debian-based systems, offering a reliable and historically significant Python environment.
Table of Contents
Section 1: Install Python 3.8 via source on Debian 12, 11 or 10
This section will guide you through installing Python 3.8 on Debian 12, 11, or 10 by compiling the source code. This method gives you the most control over the installation. It ensures you get the latest Python release, as by now, Debian 11 Bullseye and Debian 12 Bookworm onwards do not even feature Python 3.8 in their default archives.
Step 1: Update Debian System Packages Before Python 3.8 Installation on Debian
It is prudent to ensure your Debian system is up-to-date before you proceed with the installation. This step ensures that the existing packages are compatible with the ones we will install.
sudo apt update && sudo apt upgrade
Step 2: Install Development Packages for Python 3.8 on Debian
In this step, we will install a set of packages essential for compiling Python from the source. These include development libraries and other utilities used during the compilation process.
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev -y
Step 3: Download Python 3.8 Source Code on Debian 12, 11 or 10
Now, download the Python 3.8 source code from the official Python website. Make sure you have the latest version by checking the official downloads page. As of this writing, the latest security release is Python 3.8.17.
Step 4: Extract Python Archive and Move to Appropriate Directory
After downloading the source code, we need to extract it. Here, the
tar command is used for extraction.
tar -xf Python-3.8.12.tar.xz
For organizational purposes, it’s a good practice to move the extracted files to a standard location within
/usr/local/. In this guide, we will move them to
mv Python-3.8.17 /usr/local/share/python3.8
Step 5: Configure, Compile, and Install Python 3.8 on Debian 12, 11 or 10
Now, navigate to the directory containing the Python source code. We will run the
./configure script with certain flags for optimization and enabling shared libraries.
cd /usr/local/share/python3.8 ./configure --enable-optimizations --enable-shared
--enable-optimizations flag tells the script to perform several checks to ensure all dependencies are present, and optimizes the Python binary by running multiple tests. The
--enable-shared flag builds shared libraries, which are essential for certain types of applications.
You may also consider using the
--with-ensurepip=install flag to install the
pip package manager alongside Python.
Now, it’s time to compile the source code using the
For faster compilation, especially on systems with multiple CPU cores, you can use the
-j flag followed by the number of CPU cores you want to utilize. For example, if your system has 6 CPU cores, you could use 5 of them:
make -j 5
Once the compilation is complete, install the Python binaries. It’s recommended to use the
make altinstall command to avoid overwriting the default Python binary in the system.
sudo make altinstall
After the installation, configure the dynamic linker run-time bindings. This is an essential step and should not be skipped; neglecting to do so may lead to issues.
sudo ldconfig /usr/local/share/python3.8
Finally, let’s verify the installation by checking the Python version. This step is crucial to confirm that Python 3.8 was successfully installed and is ready for use.
You should see output similar to the following:
Section 2: Create a Test Virtual Environment with Python 3.8 on Debian
In this section, we’ll set up a virtual environment using Python 3.8. Virtual environments are a best practice in Python development as they isolate project-specific dependencies and avoid potential conflicts with other Python projects or system libraries.
Step 1: Create a Test Project Directory on Debian
First, we must create a directory that will hold our Python project. This is where we will set up our virtual environment. Execute the following commands to create a directory named
test_app and navigate into it:
mkdir ~/test_app cd ~/test_app
Step 2: Create a Virtual Environment in Test Dirwe’rey on Debian
Now that we have the project directory let’s create a Python virtual environment. We will use Python’s
venv module, which comes pre-installed with Python 3.3 and later versions. This module helps in creating lightweight virtual environments.
Run the following command to create a virtual environment named
python3.8 -m venv test_app_venv
-m venv indicates that we are using the
venv module. The
test_app_venv is the name of the virtual environment, and you can name it anything that makes sense for your project.
Step 3: Activating the Python Virtual Environment on Debian
With the virtual environment created, the next step is to activate it. Activating the virtual environment will isolate it, ensuring that any Python commands you run, or any Python packages you install will be confined to this environment.
Activate the Python environment:
You’ll know you’re in the virtual environment because its name will now appear on the left of the terminal prompt. For example:
This indicates that you are currently operating inside the
test_app_venv virtual environment. Any Python packages you install now will only be available within this environment.
Step 4: Deactivating the Virtual Environment on Debian
Once you are done working in the virtual environment, you can deactivate it to return to the system-wide Python environment. This is done simply by typing:
Once deactivated, the prefix in the terminal prompt will disappear, indicating that you are no longer in the virtual environment.
Section 3: Install Pip via Python 3.8 on Debian 1Python’s 10
This section will focus on installing Python’s package manager, Pip, alongside Python 3.8. Pip is an essential tool for Python developers as it facilitates installing and managing Python libraries and packages.
Step 1: Verifying the Installation of Pip on Debian
Python 3.8 usually comes with Pip installed by default. However, in some cases, Pip might not be installed, or there might be issues with the existing installation. Let’s make sure Pip is installed alongside Python 3.8:
python3.8 -m pip --version
If Pip is installed, this command will display its version. Otherwise, it’s time to install Pip manually, which we’ll do in the following steps.
Step 2: Download Pip Installation Script on Debian 12, 11 or 10
To install Pip for Python 3.8, we will download a Python script to manage the installation process. This script, named
get-pip.py, can be downloaded using the
Execute the following command to download the Pip installation script:
This command retrieves the
get-pip.py script from the official repository and saves it in the current directory.
Step 3: Install Pip for Python 3.8 on Debian 12, 11, or 10
With the script downloaded, it’s time to install Pip. Execute the following command to run the
get-pip.py script with Python 3.8:
This command tells Python 3.8 to execute the script, installing Pip.
Steit’s Upgrading Pip to the Latest Version
Even though we just installed Pip, it’s a good practice to ensure we use the latest version. Pip is actively developed; newer versions often include essential fixes and improvements.
Run the following command to upgrade3.8’sto the latest version:
python3.8 -m pip install --upgrade pip
This uses Python 3.8’s instance of Pip to upgrade to the latest version.
Conclusion and Final Thoughts
This guide explored installing Python 3.8 on a Debian 12, 11, or 10 Linux. We began by ensuring the system was updated and installing Python 3.8 from the official repositories. Additionally, we examined how to create a virtual environment to isolate our Python projects and dependencies, which is a best practice in Python development. Finally, we tackled installiPython’spgrading Pip, Python’s package manager, an essential tool for managing Python libraries.
As a recommendation, it’s critical to keep Python and its associated tools, such as Pip, updated to the latest versions. This grants access to the latest features and ensures that any security vulnerabilities are patched. In a professional setting, consistently using updated tools can significantly contribute to the efficiency and security of your Python development environment.