Install Python on Debian 1

How to Install Python 3.9 on Debian 10

Python is the most popular object-oriented, high-level programming language used by top tech companies for scripting and automation. You can easily install Python 3.9 on Debian 10 systems and use it for your projects.

Python 3.9 is the latest release. It contains all major updates, including dict operators, new str functions, support for the IANA time zone, and several improvements. It also includes major security updates and more. 

Python is an easy-to-learn object-oriented language with clean and simple syntax making it a quick choice for new and experienced developers. This tutorial will tell you how to install Python 3.9 on your Debian 10 systems step-by-step. 

What You’ll Need

For this tutorial, you will need a Debian system. Additionally, you must have an account with sudo access or a root account. To become a sudo user, you simply have to use the sudo keyword with all the commands that you execute. 

In contrast, you can become a superuser by using the su command. However, the su command will ask you for your root password.

Install Python 3.9 on Debian

There are multiple ways to install Python easily on your Debian systems. The first method is to use the apt command, and the second method is to use Python source from its official website

Install Python 3.9 on Debian with Apt

Installing Python’s latest version on Debian machines is a straightforward process. To install Python 3.9 on Debian using the apt packages manager, follow the steps listed below.

1. First, update the packages list and install required dependencies using the apt update command:

sudo apt update
Update Python on Debian

2. Secondly, install the dependencies using the command given below:

sudo apt install software-properties-common

3. After that, restart the system using the reboot command as shown below:

sudo reboot

4. Once the system has restarted, add the dead snakes PPA to your system’s sources list by typing:

sudo add-apt-repository ppa:deadsnakes/ppa

Hit the “Enter” key when you get a prompt.

5. You have successfully enabled the repository. Lastly, you can install Python 3.9 by running the command below:

sudo apt update
sudo apt install python3.9

Finally, Python 3.9 is installed on your Debian system. 

6. Finally, Python 3.9 is installed on your Debian system. To verify the installation, type the command given below:

python3.9 --version

And you will get the version of Python installed on your system.

Installing Python 3.9 on Debian 10 from Source

Installing Python 3.9 from the source is also very easy, and you can install it by following the steps given below. The steps have been numbered for your convenience.

1. Firstly, you will install the dependencies required for Python by executing the following commands:

sudo apt update
sudo apt upgrade -y
sudo reboot
sudo apt install wget software-properties-common build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev
Updated Python packages on Debian

Now, the packages might update if you have not updated them recently, or you might get a similar output:

0 upgraded, 95 newly installed, 0 to remove, and 0 not upgraded.
Need to get 74.7 MB of archives.
After this operation, 296 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Enter the “Y” key to continue the installation.

2. Secondly, get the latest release source code from the Python download page with the wget command.

wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
Install Python package on Debian

This will successfully install the Python package. 

3. Thirdly, you have to extract the package after downloading. You can extract the package using the tar command.

tar -xf Python-3.9.1.tgz

4. After you have extracted the package, navigate to the Python directory using the cd command and configure it as shown in the command given below:

cd Python-3.9.1
./configure --enable-optimizations

It will give you a similar output:

Install
--enable-optimizations optimize Python binary for running tests. 
....
checking for shm_open... yes
checking for shm_unlink... yes
checking for pkg-config... no
checking for openssl/ssl.h in /usr/local/ssl... no
checking for openssl/ssl.h in /usr/lib/ssl... no
…...
creating Modules/Setup.local
creating Makefile

5. Now that you have configured Python, it is time to start the build process. To build Python, execute this command:

make -j 2

Additionally, you can modify -j to correspond to the number of cores in your processor. Furthermore, through the nproc command, you can find the number of the cores in your system.

6. After that, the next step is to install Python libraries using the command given below.

sudo make altinstall

Altinstall will overwrite the default system Python3 binary.

Sample output is shown below:

....
changing mode of /usr/local/lib/python3.9/lib-dynload/__pycache__ to 755
running install_scripts
copying build/scripts-3.9/idle3.9 -> /usr/local/bin
...
changing mode of /usr/local/bin/idle3.9 to 755
...
rm /usr/local/lib/python3.9/lib-dynload/_sysconfigdata__linux_x86_64-linux-gnu.py
…
Looking in links: /tmp/tmpog4qrruc
Requirement already up-to-date: setuptools in /usr/local/lib/python3.9/site-packages (49.2.1)
Requirement already up-to-date: pip in /usr/local/lib/python3.9/site-packages (20.2.3)

7. Finally, Python 3.9 is installed on your Debian systems. To verify the version, type this command: 

Python version
python3.9 --version
Output: Python 3.9.1

8. Additionally, if you want to install Python modules available on the modules releases page, use the pip command as shown in the syntax.

python3.9 -m pip install <module>

Running Python 3.9 After Installation

To use Python 3.9 shell, type “python” with its version number. It will open a Python shell for you. 

$ python3.9
Open

To print anything on Python shell, type the command as shown below:

>>> print("Hello World")
Output: Hello World

Lastly, to close Python interactive shell session, type the “exit” command. 

>>> exit()

You have seen how to install Python 3.9 on Debian 10 using source code. You can run the virtual environment now and develop your Python projects. Additionally, you can update the Python package, if there is a newer version.

If you liked this post, please share it with your friends. In case of suggestions or queries, leave a comment below.

If this guide helped you, please share it.

Related Posts