Python 3.9.1 on Debian 10

15 Free Courses to Learn Python in 2021 | by javinpaul | The Startup |  Medium

Debian 10 includes Python 3.7 and Python 2.7.
Python 2.7 is hopelessly out of date and not supported anymore since January 1, 2020. Also, Python 3.7 is getting old. New stuff is always being developed and today I want to show you how to compile and how to deploy Python version 3.9.1.

Python 3.9.1 has been released on 7 December 2020. Release notes can be found here

1 Install all the needed packages so that you can compile Python 3.9.1 including some features like lzma.

sudo apt install wget build-essential libreadline-gplv2-dev libncursesw5-dev \ 
libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev liblzma-dev

2 Download the Python 3.9.1 tar ball and unpack it.
I use always: ~/Download for these matters.

cd ~/Downloads
tar xfvz Python-3.9.1.tgz

3 Compile Python
With the flag -j you can define the number of cores your computer has. This will speed up the compilation time. In my case seven. To play it safe I’ll define here two cores.

cd Python-3.9.1
./configure --enable-optimizations
make -j 2 

4 Install Python-3.9.1
Always use the `makeall` install option. If you run make install it will possibly break your system, because it will replace the default Python 3 version on your system!

sudo makealtinstall

5 Check if installation went correctly

python3.9 --version 

Remember, always use a virtual environment when developing code.

Leave a Comment