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 /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/Python-3.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 greatly 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 installed 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 activating 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#
By default, pip 3.8 should be installed, which is the most used package manager for Python.
To exit the virtual environment, use the following command:
Comments and Conclusion
In the tutorial, you have learned how to install Python 3.8 for Debian 11 Bullseye and create a quick 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.