Lesson 2
The Basic Elements
Chapter 2: Installing Python
Installing Python on Unix/Linux
You can skip straight to the next page if you are not using Unix/Linux.
Unix/Linux-based Operating Systems come in different distributions.
The machines in the department’s labs run on Ubuntu (the most popular Linux distribution). As of May 2024, the machines run on Ubuntu 22.04. We are expecting them to be upgraded to Ubuntu 24.04 over the summer, in time for the new academic year in September 2024.
Python should already be correctly set up on the lab machines, so there is no need to install anything there. The following instructions are only for if you are using your Linux distribution on your own machine.
Check your system installation version of Python
Most Unix/Linux distributions should come with a system installation version of Python. For example, Ubuntu 24.04 comes installed with Python 3.12 by default.
Type the following into your Unix/Linux terminal window to check the Python version of the system installation. -V
is short for version (you can also use python --version
instead).
$ python -V
Python 3.12.4
If this does not work, it is because python
has not been set up as an alias on your system to point to the correct Python interpreter. Older Linux distributions distinguish between Python 2 (no longer supported) and Python 3. So you may need to explicitly type python3
instead to run Python 3:
$ python3 -V
Python 3.10.6
In any case, do not try to upgrade or mess with this installation unless you know what you are doing - you might break your operating system otherwise! Some parts of your operating system might rely on this particular installation!
Install a user installation version of Python
If your Python version is at least 3.12, then perfect! You do not need to do anything more - move on to the next page!
If the version is less than 3.12, then you might want to install your own user installation of Python 3.12 alongside the system installation version, because again there is a risk of this version of Python being needed for something else.
You will end up invoking your new user installation using python3.12
instead.
I will assume you are using a Ubuntu machine, which has the apt
package manager on your machine. If you are using a different distribution, use the appropriate package manager that comes with your distribution.
Run the following to set up a user installation of Python 3.12 on your machine:
user@MACHINE:~$ apt-get update
user@MACHINE:~$ apt-get install -y python3.12 python3.12-venv python3-venv
Check your user installation of Python
Once you have set up your user installation version of Python, type in the following to check that it has been installed correctly.
user@MACHINE:~$ python3.12 -V
Python 3.12.6
Your operating system may have automatically aliased python3.12
with python3
, depending on whether a Python 3 installation existed before you installed Python 3.12 or not.
So you might also be able to run python3
instead of python3.12
as a shortcut. Just make sure this is the version you want.