{"id":10327,"date":"2021-09-28T09:44:41","date_gmt":"2021-09-28T09:44:41","guid":{"rendered":"https:\/\/linuxways.net\/?p=10327"},"modified":"2021-09-28T09:44:41","modified_gmt":"2021-09-28T09:44:41","slug":"how-to-install-python-3-9-on-debian-11","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/debian\/how-to-install-python-3-9-on-debian-11\/","title":{"rendered":"How to Install Python 3.9 on Debian 11"},"content":{"rendered":"<p>Python is arguably one of the most popular and versatile programming languages. It\u2019s a multi-purpose language and provides a myriad of use cases such as the development of full stack web apps, artificial intelligence, web scraping, and visualization of data in cool dashboards in data science.<\/p>\n<p>Currently,<a href=\"https:\/\/www.python.org\/downloads\/release\/python-397\/\"> Python 3.9.7<\/a> is the latest version of Python and provides quite a number of benefits including flexible variable and function notations, union operators in dict, support for IANA timezone and <a href=\"https:\/\/www.python.org\/downloads\/release\/python-397\/\">so many others<\/a>.<\/p>\n<p>In this guide, we will walk you through the installation of Python 3.9 on Debian 11.<\/p>\n<h2><strong>Step 1: Install Python3 dependencies<\/strong><\/h2>\n<p>This walkthrough will require us to compile Python from source. This allows us to install the latest version of Python and further customize build options.<\/p>\n<p>To get started, update the package index.<\/p>\n<pre><strong>$ sudo apt update<\/strong><\/pre>\n<p>Next, install the dependencies and libraries required to build Python.<\/p>\n<pre><strong>$ sudo apt install build-essential libncurses5-dev zlib1g-dev libnss3-dev libgdbm-dev libssl-dev libsqlite3-dev libffi-dev libreadline-dev curl libbz2-dev<\/strong><\/pre>\n<p>This installs a host of additional packages and other dependencies.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"984\" height=\"245\" class=\"wp-image-10333\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-438.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-438.png 984w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-438-300x75.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-438-768x191.png 768w\" sizes=\"auto, (max-width: 984px) 100vw, 984px\" \/><\/strong><\/p>\n<p>Once the installation of Python dependencies is complete, the next step will be to download the latest Python 3.9 installation file.<\/p>\n<h2><strong>Step 2: Download and install the latest Python 3.9<\/strong><\/h2>\n<p>Next, we will download the gzipped source code file from the Official Python release and download page as shown.<\/p>\n<p>So, to download the tarball file, run the command:<\/p>\n<pre><strong>$ sudo wget https:\/\/www.python.org\/ftp\/python\/3.9.7\/Python-3.9.7.tgz<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"967\" height=\"259\" class=\"wp-image-10334\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-439.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-439.png 967w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-439-300x80.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-439-768x206.png 768w\" sizes=\"auto, (max-width: 967px) 100vw, 967px\" \/><\/p>\n<p>Next, extract the compressed file as follows.<\/p>\n<pre><strong>$ tar -xvf Python-3.9.1.tgz<\/strong><\/pre>\n<p>After the extraction, you will now have 2 files: the tarball file and the decompressed folder ( Python-3.9.7)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"109\" class=\"wp-image-10335\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-440.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-440.png 700w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-440-300x47.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>To compile Python from source navigate to the uncompressed folder.<\/p>\n<pre><strong>$ cd Python-3.9.1<\/strong><\/pre>\n<p>Then run the configure script as shown.<\/p>\n<pre><strong>$ \/configure --enable-optimizations<\/strong><\/pre>\n<p>This runs multiple tests and takes quite some time. In my case, this took approximately 30 minutes. Here is some sample output.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"740\" height=\"289\" class=\"wp-image-10336\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-441.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-441.png 740w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-441-300x117.png 300w\" sizes=\"auto, (max-width: 740px) 100vw, 740px\" \/><\/p>\n<p>Then commence the build process.<\/p>\n<pre><strong>$ make -j 2<\/strong><\/pre>\n<p>The <strong>-j <\/strong>option specifies the number of CPU cores. You can check out the number of cores on your Linux system by executing the <strong>nproc<\/strong> command.<\/p>\n<pre><strong>$ nproc<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"431\" height=\"88\" class=\"wp-image-10337\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-442.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-442.png 431w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-442-300x61.png 300w\" sizes=\"auto, (max-width: 431px) 100vw, 431px\" \/><\/strong><\/p>\n<p>Here\u2019s some sample output of the build process.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"984\" height=\"213\" class=\"wp-image-10338\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-443.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-443.png 984w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-443-300x65.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-443-768x166.png 768w\" sizes=\"auto, (max-width: 984px) 100vw, 984px\" \/><\/strong><\/p>\n<p>Afterward, run the following command to install Python binaries.<\/p>\n<pre><strong>$ sudo make altinstall<\/strong><\/pre>\n<p>This finalizes the installation of Python 3.9.7 on your system.<\/p>\n<h2><strong>Step 3: Testing the installation<\/strong><\/h2>\n<p>You can confirm the version of Python installed using the command:<\/p>\n<pre><strong>$ python3.9 --version<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"469\" height=\"94\" class=\"wp-image-10339\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-444.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-444.png 469w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-444-300x60.png 300w\" sizes=\"auto, (max-width: 469px) 100vw, 469px\" \/><\/p>\n<p>You can access Python 3.9 shell using the command<\/p>\n<pre><strong>$ python3.9<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"682\" height=\"206\" class=\"wp-image-10340\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-445.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-445.png 682w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-445-300x91.png 300w\" sizes=\"auto, (max-width: 682px) 100vw, 682px\" \/><\/strong><\/p>\n<p>To give it a test run, we will write a simple program to find the sum of two variables, x and y.<\/p>\n<pre><strong>x = 35<\/strong>\r\n\r\n<strong>y = 75<\/strong>\r\n\r\n<strong>z = x + y<\/strong>\r\n\r\n<strong>print(\"Hello, the sum of x and y is\", +z)<\/strong><\/pre>\n<p><strong>Output<\/strong><\/p>\n<p><strong>Hello, the sum of x and y is 110<\/strong><\/p>\n<p>And there we go! Python 3.9.7 is now installed on Debian 11.<\/p>","protected":false},"excerpt":{"rendered":"<p>Python is arguably one of the most popular and versatile programming languages. It\u2019s a multi-purpose language and provides a myriad of use cases such as the development of&hellip;<\/p>","protected":false},"author":1,"featured_media":10601,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[521,10],"class_list":["post-10327","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-debian","tag-debian-11","tag-python"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/10327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=10327"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/10327\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/10601"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=10327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=10327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=10327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}