Install Python 3.9 on Debian 10 - Step by Step Process ?








Python is a programming and scripting language used to build Desktop applications, automation scripts, Web applications, Games, Big data applications and so on.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related Python queries.

In this context, we shall look into method to install Python on Debian Linux System.


How to Install Python 3.9 on Debian ?

As earlier mentioned Python is a programming and scripting language developed under open source license, making it freely usable and distributable, even for commercial use.

Compiling Python from the source allows to install the latest Python version and customize the build options.


1. Update System APT cache index

i. Start by updating APT cache index before installing Python 3.9 on Debian 10 system.

$ sudo apt update

ii. If upgrade is possible, then run the commands below:

$ sudo apt upgrade -y

iii. Then, restart the system after a successful upgrade.

$ sudo reboot


2.  Install dependency packages

i. After the system is rebooted, install dependency packages:

$ sudo apt install wget software-properties-common build-essential libnss3-dev zlib1g-dev libgdbm-dev libncurses5-dev libssl-dev libffi-dev libreadline-dev libsqlite3-dev libbz2-dev

ii. To proceed, Hit the y key to begin installation:

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


3. Downloads Python

i. To download Python, visit Python Downloads page  and pull the latest release:

$ wget https://www.python.org/ftp/python/3.9.2/Python-3.9.2.tgz

ii. Extract the downloaded file.

$ tar xvf Python-3.9.2.tgz

iii. Change working directory to create Python folder:

$ cd Python-3.9.2/

iv. Run configuration command:

$ ./configure –enable-optimizations

Sample output:

….
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
checking for openssl/ssl.h in /usr/ssl… no
checking for openssl/ssl.h in /usr/pkg… no
checking for openssl/ssl.h in /usr/local… no
checking for openssl/ssl.h in /usr… no
checking whether compiling and linking against OpenSSL works… no
checking for –with-ssl-default-suites… python
checking for –with-builtin-hashlib-hashes… md5,sha1,sha256,sha512,sha3,blake2
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Misc/python.pc
config.status: creating Misc/python-embed.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
config.status: pyconfig.h is unchanged
creating Modules/Setup.local
creating Makefile

v. To Build Python 3.9 on Debian 10 Linux, run the command immediately:

$ sudo make altinstall

Usually, a successful installation will have output similar to 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
copying build/scripts-3.9/pydoc3.9 -> /usr/local/bin
copying build/scripts-3.9/2to3-3.9 -> /usr/local/bin
changing mode of /usr/local/bin/idle3.9 to 755
changing mode of /usr/local/bin/pydoc3.9 to 755
changing mode of /usr/local/bin/2to3-3.9 to 755
rm /usr/local/lib/python3.9/lib-dynload/_sysconfigdata__linux_x86_64-linux-gnu.py
rm -r /usr/local/lib/python3.9/lib-dynload/__pycache__
/usr/bin/install -c -m 644 ./Misc/python.man \
/usr/local/share/man/man1/python3.9.1
if test “xupgrade” != “xno” ; then \
case upgrade in \
upgrade) ensurepip=”–altinstall –upgrade” ;; \
install|*) ensurepip=”–altinstall” ;; \
esac; \
./python -E -m ensurepip \
$ensurepip –root=/ ; \
fi
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)


4. Verify Python Installation

Now, execute the commands below will output the version of Python 3.9 available in our system:

$ python3.9 –version
Python 3.9.2


5.  Install Python modules

Finally, to install Python modules available in modules releases page, use the command syntax:

$ python3.9 -m pip install <module>


How to Install Python 3.9 on Debian 10 with Apt ?

Install Python 3.9 on Debian using the apt packages manager is a very easy process. All you need to do is to follow the steps outlined below:

1. Update packages list

First, update the packages list and install required dependencies:

$ sudo apt update
$ sudo apt install software-properties-common


2. Enable Repository

Then, add the deadsnakes PPA to system's sources list by typing:

$ sudo add-apt-repository ppa:deadsnakes/ppa

Hit the Enter when we get prompt.


3. Install Python 3.9

Once the repository is enabled, we can install the Python 3.9 by running the below command:

$ sudo apt update
$ sudo apt install python3.9


4. Finally, verify Installation

To verify the installation, execute the command:

$ python3.9 –version
Python 3.9.0+

At this stage, the Python 3.9 is installed on Debian 10 system.


How to Upgrade from Python 3.7 to 3.9 in Debian 10 ?

In order to, upgrade the version of Python from 3.7 to 3.9, we need to add Debian's testing repositories.

1. Open the /etc/apt/sources.list file with the following command:

$ sudo nano /etc/apt/sources.list

2. Add the official testing repository. Append the following line of text to the end of the file:

$ deb http://http.us.debian.org/debian/ testing non-free contrib main

Our file should match this:

File: /etc/apt/sources.list
deb http://mirrors.linode.com/debian buster main
deb-src http://mirrors.linode.com/debian buster main
deb http://mirrors.linode.com/debian-security buster/updates main
deb-src http://mirrors.linode.com/debian-security buster/updates main
# buster-updates, previously known as ‘volatile’
deb http://mirrors.linode.com/debian buster-updates main
deb-src http://mirrors.linode.com/debian buster-updates main
# Debian Testing Non-Free
deb http://http.us.debian.org/debian/ testing non-free contrib main

3. After editing the file, download the information for all of the packages available with the following command:

$ sudo apt update

4. Upgrade Python 3 with the following command:

$ sudo apt upgrade python3

Because Python3 requires a lot of dependencies, we are prompted to allow Debian to restart certain services. If we are not running any active processes, this is okay.

Otherwise, we may decide to restart the services ourselves.

5. Verify that we have updated Python by checking the version:

$ python3 –version
Python 3.9.1

Now Debian 10 system has the latest version of Python 3 installed.


[Need urgent assistance in fixing CyberPanel errors? – We're available 24*7  . ]



Conclusion

This article covers Python installation on Debian Linux System. Basically, Python is a programming and scripting language developed under open source license, making it freely usable and distributable, even for commercial use. 

Python 3.9 is the latest major release of the Python language. It includes many new features such as new dict operators, new str functions, support for IANA time zone, and more.


After Python 3.9 installation on your Linux System, you can verify it easily by running the command:

python3.9 --version

The output should show the Python version installed.


For Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on LinuxAPT.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com