Install & Run Python#

Before you can run, you must first walk (or slither).

In order to get Python running on your machine, you need to either install it directly or run it through an intermediary. There are many different ways to do this.

We will highlight a simple way to get started and three more permanent options. All of these will work just fine for our courses.

Looking for the simplest way to get started?

Use JupyterLab in your browser with no installation required here.

This is the easiest way to get started, as no installation is required. Your notebooks are stored in the browser-based environment rather than as files directly on your computer. This can be a good way to get started, but it has some limitations and may not be suitable for more advanced use. You can always install Python and JupyterLab locally later, as described in Method 1 below.


Method 1: Install Python and JupyterLab#

The first of the three options we would like to highlight - and the one which we personally prefer - is to download and install Python and JupyterLab. This installs the software directly on to your computer.

It is slightly technical, as you will have to initiate the program through your computer’s Terminal/PowerShell, but once running it is far less finicky than the other options with respect to uploading or downloading files that you might use in your coding. A detailed set of instructions for both Mac and PC users can be found on this page.

Method 1: Mac#

How to Install Python on macOS#

Python 2 comes preinstalled on older versions of macOS. This is no longer the case for current versions of macOS, starting with macOS Catalina.

No mattter which version of macOS you have installed, we would like you to install Python 3.

How to Check Your Python Version on a Mac#

To check which Python version you have on your Mac, first open a command-line application, such as Terminal.

Check the Python version in the Terminal:

python --version

Check the Python 3 version:

python3 --version

Attention

When typing python3 --version the Terminal may give you a notice saying no developer tools were found
 and give you a pop-up screen with the choice to install these develper tools.

We recommend that you skip this installation as it is slow and tedious and should be solved by the Python installation process described below.

If you have Python installed, one or more of these commands should respond with a version number.

For example, if Python 3.12.5 is already set up on your computer, then the python3 command will display that version number:

Input

python3 --version

Output

Python 3.12.5

You’ll want to get the latest version of Python if any of these conditions are true:

  • None of the above commands returns a version number.

  • The only version you see displayed is in the Python 2.X series.

  • You have a version of Python 3 that isn’t the latest available (which was version 3.12.5 as of this writing). You can find the newest version number here.

Install Python on Mac#

Now that you have checked if you already have a version of Python, you are ready to download and install.

This is the most reliable installation method on macOS. It includes all the system dependencies needed for developing applications with Python.

You can install from the official installer in two steps.

Step 1: Download the Official Installer

Follow these steps to download the full installer:

  • Open a browser window and navigate to the Python.org Downloads page.

  • Download the latest version for macOS.

  • When the installer is finished downloading, move on to the next step.

Step 2: Run the Installer

Run the installer by double-clicking the downloaded file.

Follow these steps to complete the installation:

  • Press Continue a few times until you’re asked to agree to the software license agreement. Then click Agree.

  • You’ll be shown a window that tells you the install destination and how much space it will take. You most likely don’t want to change the default location, so go ahead and click Install to start the installation.

  • When the installer is finished copying files, double-click the Install Certificates command in the finder window to make sure your SSL root certificates are updated.

Congratulations—you now have the latest version of Python 3 on your macOS computer!

You can now move on to install JupyterLab.

Method 1: Windows#

How to Install Python on Windows#

As mentioned above there are several ways of installing Python on your Windows computer. The following guide works by downloading the latest version of Python from Python.org. But before you do that it is a good idea to check whether a version on Python is already installed on your computer.

How to Check Your Python Version on Windows#

To check if you have any version of Python and which version you have on Windows, first open a command-line application, such as Windows PowerShell.

Check the Python version by typing the following into the PowerShell

python --version

If you have Python installed then this command should respond with a version number:

Python 3.12.5

Attention

If you don’t have a version of Python on your computer the above command will launch Microsoft Store where you can find a Python application.

Do not download this version of Python! Instead follow the steps below.

You’ll want to get the latest version of Python if any of these conditions is true:

  • The command above does not return a version number.

  • You have a version of Python 3 that isn’t the latest available (which was version 3.12.5 as of this writing). You can find the newest version number here.

Install Python on Windows#

Installing Python from the official installer is the most reliable installation method on Windows. It includes all the system dependencies needed for developing applications with Python. However, it can cause some trouble, so read the following guide carefully.

You can install from the official installer in two steps.

Step 1: Download the Official Installer#

Follow these steps to download the full installer:

  • Open a browser window and navigate to Python.org.

  • NOTE: In the drop down menu called “Downloads” click “get the standalone installer for Python 3.x.x.”

  • The download should start instantly.

When the installer is finished downloading, move on to the next step.

Step 2: Run the Installer#

Run the installer by double clicking on the downloaded .exe file.

Follow these steps to complete the installation:

  • Select the box “Install launcher for all users” this allows all users of the computer to use the Python launcher application.

  • NOTE: Select the box “Add Python 3.x to PATH” this enables you to launch Python from the command line.

  • Click “Install Now”.

  • Click the “Disable path length limit”. This removes the limitation of the path lenghts and can smoothe over any issues in the future with the path length.

  • Press “Close” to finish the installation.

Check your version of Python#

Now that you have installed Python, it is a good idea to check if it was done succesfully.

Open PowerShell and write:

python --version

Now this should return the version of Python you have just installed

Python 3.12.5

Congratulations - you now have the latest version of Python 3 on your computer!

Install JupyterLab - both Mac and Windows#

Now you need to install JupyterLab, the Integrated development environment (IDE) we will be using in this course.

We will install this from the Terminal (Mac) or PowerShell (Windows) using pip.

Pip is a package manager which allows you to easily install and manage Python libraries and packages - don’t worry if this doesnt make a lot of sense right now, we will get back to what that means in the course.

Pip should have been installed together with Python.

Type the following in the Terminal/PowerShell:

pip install jupyterlab

Or sometimes you will need to write:

pip3 install jupyterlab

An installation will start in the Terminal/PowerShell - when it finishes, type the following and the notebook will launch.

jupyter lab

Now you are ready to learn how to code in Python!


Method 2: Google Colab#

Google Colab is an easy way to get started, as all it requires is a Google account. After you login, you simply create a new notebook and start coding.

You can connect your Google Drive to upload files that you want to work with. If you only upload your files directly to Colab, you can work on them, but they will be erased when you close your session or if your session times out, at which point you will need to re-upload your files.

You can read more about Google Colab here. We would also advise that Google is a corporate third party, who mostly want to sell your data so that other people can sell you stuff that Google predicts you will want (hello age of surveillance capitalism). While this might not mean much for this course, we would urge caution if you are uploading datasets with sensitive data into Google Colab.


Method 3: ERDA#

Copenhagen University provides its students and staff with access to its Electronic Research Data Archive (ERDA).

ERDA includes a built-in copy of Jupyter Notebook, which runs the newest version of Python.

Simply select the Jupyter Notebook icon after logging in, then select Start DAG, and continue on to your coding space.

Be aware that ERDA cannot read local files off of your computer so you must, like Google Colab, upload any files you wish to work with. Unlike Google Colab, however, ERDA will maintain your files over time, saving you the trouble of worrying about different file pathways in your code.

ERDA’s self description as well as its terms and conditions can be read here.