By default, Debian 11 Bullseye does not come with Python 3.8 in its repositories, unlike some other distributions such as Ubuntu. Python 3.9 is now the latest stable feature release series of Python 3, with Python 3.10 still in beta.
To run some applications or frameworks on Debian 11, you may need to install Python 3.8 on your system, for example, using the Swift programming framework given it built to utilize Ubuntu’s LTS versions that still run the older versions of Python by default. Python 3.8 is currently being worked on for security releases, but it is advisable to upgrade to newer versions if you are developing applications.
In the following tutorial, you will learn how to download the latest version of Python 3.8, compile and make it on your Debian 11 Bullseye operating system.
Table of Contents
- Recommended OS: Debian 11 Bullseye
- User account: A user account with sudo privilages or root access (su command).
- Required Packages: wget
Updating Operating System
Update your Debian 11 operating system to make sure all existing packages are up to date:
sudo apt update && sudo apt upgrade
Root or Sudo Access
By default, when you create your account at startup with Debian compared to other distributions, it does not automatically receive sudoers status. You must either have access to the root password to use the su command or visit our tutorial on How to Add a User to Sudoers on Debian.
Install Python 3.8
Once you have got the download link, use the wget command to download the Python 3.8 archive:
Extract the Python archive. Remember, change the version number if you downloaded a newer one:
tar -xf Python-3.8.12.tar.xz mv Python3.8.12 /opt/Python3.8.12
Now install the dependencies required to install Python 3.8:
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
Navigate to the directory and run the ./configure –enable-optimizations command:
cd /opt/Python3.8.12/ ./configure --enable-optimizations --enable-shared
Note, The script performs several checks to make sure all of the dependencies on your system are present. The ./configure –enable-optimizations will optimize the Python binary by running multiple tests, which will make the build process slower.
Now that you have built and configured the environment, it is time to compile it with the command make.
A handy trick is to specify the -j <number of cpu> as this can significantly increase compiling speed if you have a powerful server. For example, the LinuxCapable server has 6 CPUs, and I can use all 6 or at least use 4 to 5 to increase speed.
make -j 6
Once you have finished building, install Python binaries as follows:
sudo make altinstall
Note, it’s advised to use the make altinstall command NOT to overwrite the default Python 3 binary system.
Next, after the installation, you need to configure the dynamic linker run-time bindings:
sudo ldconfig /opt/Python3.8.12
Note, do not skip this, or you will face issues. You will also need to replace the path with your directory name and version.
Confirm that Python 3.8 is installed and the build version by running the following command:
Create a Virtual Environment
Python’s venv module is a virtual environment is a Python environment such that the Python interpreter, libraries, and scripts installed into it are isolated from those established in other virtual environments, and (by default) any libraries installed on your operating system, for example, those that are installed on your Ubuntu operating system to avoid clashing and disturbing your production environments.
To make sure Python 3.8 is installed correctly and functioning, create a quick Python project as follows.
First, create the project directory and navigate to it:
mkdir ~/test_app && cd ~/test_app
Now inside the project root directory, run the following command to create a virtual environment, for the test name it test_app:
python3.8 -m venv test_app_venv
Next, activate the virtual environment as follows:
After starting the virtual environment you will now be in the shell prompt terminal. You will notice the name of your environment will be prefixed.
(test_app_venv) [email protected]:~/test_app#
To exit the virtual environment, use the following command:
By default, PIP 3.8 should be installed. For those with PIP issues, an alternative method is to install the package manager manually.
This can be done in several ways. One of the most common is as follows.
Log back into your environment, then download get-pip.py using the wget command.
Next, install the file downloaded.
Once installed, it is a good idea to check for upgrades.
python3.8 -m pip install --upgrade pip
Now verify the PIP 3.8 version installed:
(test_app_venv) [email protected]:/opt/Python3.8.12# pip3.8 --version pip 21.2.4 from /opt/Python3.8.12/test_app_venv/lib/python3.8/site-packages/pip (python 3.8)
Comments and Conclusion
You have learned how to install Python 3.8 for Debian 11 Bullseye in the tutorial and create an immediate virtual environment. Overall, it is advised if you are in development to move to Python 3.9 in the future, but using Python 3.8 is still safe as the Python Software Foundation is maintaining it.