This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 2: Installing Python

Installing Python on Unix/Linux

face Josiah Wang Ivan Procaccini

You can skip straight to the next page if you are not using Unix/Linux.

A Unix-based may already come with a system Python pre-installed.

Most Unix-based Operating Systems nowadays should already come with a version of Python, known as the system installation. The system installation of Python is very rarely the most up-to-date available version of the language.

Type this into your terminal window to check the Python version of the system installation. It is likely to be Python 2 (which is no longer officially supported).

$ python -V

Don’t try to upgrade or mess with this installation - you might break your operating system if you do not know what you are doing! Some parts of your operating system might rely on this particular installation!

Your Unix/Linux operating system might also come with a Python 3 installation. For example, Ubuntu 20.04 should already come with Python 3.8. Type the following to check.

$ python3 -V

If the version is at least 3.8, then perfect! You do not need to do anything more.

If the version is less than 3.8, then you might want to install your own user installation of Python 3.8 alongside this version, because again there is a risk of this version of Python being needed for something else if you upgraded it directly.

You will end up invoking your new installation using python3.8 instead.

Ubuntu is the most popular Linux distribution. So, I will assume the presence of the apt package manager on your machine.

Should you happen to work on another distribution with a different package manager, you should find that there’s a suitable alternative with it to install what you need.

Installing Python 3.8 on Ubuntu 18.04 or above

Run the following to install Python 3.8 on your machine:

user@MACHINE:~$ apt-get update
user@MACHINE:~$ apt-get install -y python3.8 python3.8-venv python3-venv

Installing Python 3.8 on Ubuntu 16.04 or lower

Run the following to install Python 3.8 on your machine:

user@MACHINE:~$ apt-get update
user@MACHINE:~$ apt-get install software-properties-common
user@MACHINE:~$ add-apt-repository ppa:deadsnakes/ppa
user@MACHINE:~$ apt-get update
user@MACHINE:~$ apt-get install -y python3.8 python3.8-venv python3-venv

Check installation

Once you have installed Python, type in the following to check that Python has been installed correctly.

user@MACHINE:~$ python3.8 -V
Python 3.8.6

Your operating system may have aliased python3.8 with python3, depending on whether a Python 3 installation existed before you installed Python 3.8 or not.

So you might also be able to run python3 instead of python3.8 as a shortcut. Just make sure this is the version you want.