DEV Community

loading...
Cover image for How To Install Python on Debian

How To Install Python on Debian

tominekan profile image Tomi Adenekan ・2 min read

Python is a very popular language for all sorts of things like Web Development, Machine Learning (and Data Analysis), Scripting, and other areas. It has become one of the most popular programming languages on Earth with a large community of developers, so, lets get started.

Warning:

  • If you have come to this tutorial because your installation of python failed, run these commands (replace <python_version> with the version of your broken installation):
sudo updatedb
sudo rm -rfv /usr/local/bin/<python_version> # or /usr/bin/<python_version>
sudo rm -rfv `locate <python_version>`
sudo updatedb
locate <python_version>
Enter fullscreen mode Exit fullscreen mode

The last command should give you nothing.

Note:

  • python3.9 is can be replaced with your python version.

Preparation:

  • In order to install python fully, some tools to build python need to be installed, open up the terminal and type:
sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev tk-dev liblzma-dev lzma
Enter fullscreen mode Exit fullscreen mode

Installation:

wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
Enter fullscreen mode Exit fullscreen mode
  • Inflate the python .tar.gz or .tgz file by typing:
tar -xf Python-3.9.0.tar.xz # or tar -xf Python-3.9.0.tgz
rm -v Python-3.9.0.tar.xz # or rm -v Python-3.9.0.tgz
Enter fullscreen mode Exit fullscreen mode
  • Change Directory into the Python Folder and start configuring python by typing:
cd Python-3.9.0
./configure --enable-optimizations
Enter fullscreen mode Exit fullscreen mode

This should look something like this:
Image Of Python Configuring
Image Of Python Configuring

  • To build python, run:
make -j `nproc` # Optimized for the number of processors the computer has
Enter fullscreen mode Exit fullscreen mode

It should look like this:
Image of Python Being Built
Image of Python being built

  • To Install python, run:
sudo make altinstall
Enter fullscreen mode Exit fullscreen mode

We use altinstall to avoid replacing other versions of python with this one (it tends to break things on the computer).

This should look like:
Sudo Make Altinstall Process
Sudo Make Altinstall Process

  • Finally, to test if python was successfully installed, type:
python3.9 --version
Python 3.9.0
Enter fullscreen mode Exit fullscreen mode

Discussion (0)

pic
Editor guide