3  Installation & Setup

3.1 Overview

The course materials are designed to be run on a personal computer. The required software is freely available online, with installation instructions provided below.

3.2 Step 1: Install Python

In this course, we will be using Python 3 with some of its most popular scientific libraries.

Python 3 itself can be downloaded and installed from https://www.python.org/downloads/. Follow the steps on this website to download and install Python 3.14.x for Windows or macOS. Just ask for help during the practical sessions or on Teams when something isn’t clear.

3.3 Step 2: Install JupyterLab

We will teach the basics of Python programming using JupyterLab, a scripting environment that runs in a web browser.

Follow these steps to install JupyterLab:

  1. Open a Windows PowerShell terminal.

  2. Create a directory for the course, for example pmi, and enter it:

    cd ~       # Changes directory to your home directory.
    mkdir pmi  # Makes a directory named 'pmi'.
    cd pmi     # Changes directory into 'pmi'. 
  3. Inside the pmi directory, run this command to create a so-called virtual environment (venv):

    py -V:3.14 -m venv .venv  # Creates a Python 3.14 virtual environment in '.venv'

    (In week 4, we will discuss the benefits of these virtual environments)

  4. Activate the virtual environment:

    Set-ExecutionPolicy Unrestricted -Scope CurrentUser  # Allow the execution of scripts.
    .\.venv\Scripts\Activate.ps1  # Runs the script 'Activate.ps1' to activate the virtual environment.

    The terminal should now show the name of the virtual environment in front of the prompt.

  5. Install a few Python packages that we will use throughout the course:

    pip install jupyterlab numpy matplotlib ipympl pandas pillow pydicom pylibjpeg pylibjpeg-libjpeg nibabel pmi-viewer  # Installs several packages.

    (Note: this may take a few minutes.)

  6. Start JupyterLab:

    jupyter-lab  # Starts JupyterLab.
  7. Keep the terminal open while you’re working with JupyterLab! When you’re finished, just close the terminal app and browser tab.

When you need to start JupyterLab again, just repeat steps 4 and 6.

  1. Open the Terminal app.

  2. Create a directory for the course, for example pmi, and enter it:

    cd ~       # Changes directory to your home directory.
    mkdir pmi  # Makes a directory named 'pmi'.
    cd pmi     # Changes directory into 'pmi'. 
  3. Inside the pmi directory, run this command to create a so-called virtual environment (venv):

    python3.14 -m venv .venv  # Creates a Python 3.14 virtual environment in '.venv'

    (In week 4, we will discuss the benefits of these virtual environments)

  4. Activate the virtual environment:

    source .venv/bin/activate  # Runs the script 'activate' to activate the virtual environment.

    The terminal should now show the name of the virtual environment in front of the prompt.

  5. Install a few Python packages that we will use throughout the course:

    pip install jupyterlab numpy matplotlib ipympl pandas pillow pydicom pylibjpeg pylibjpeg-libjpeg nibabel pmi-viewer  # Installs several packages.

    (Note: this may take a few minutes.)

  6. Start JupyterLab:

    jupyter-lab  # Starts JupyterLab.
  7. Keep the terminal open while you’re working with JupyterLab! When you’re finished, just close the terminal app and browser tab.

When you need to start JupyterLab again, just repeat steps 4 and 6.

Before executing Activate.ps1, run this to allow the execution of scripts:

Set-ExecutionPolicy Unrestricted -Scope CurrentUser

If that doesn’t help, then run

$env:Path = "$PWD\.venv\Scripts;$env:Path"

instead of .\.venv\Scripts\Activate.ps1. Note that the terminal will not show the environment’s name, but it should work nonetheless.

Try running python -m pip instead.

Try running python -m jupyterlab instead.

This script is meant to be executed in a Windows PowerShell terminal. From a classic Windows Command Prompt, you could run the .bat script instead:

.\.venv\Scripts\Activate.bat

This happens when jupyter-lab is stopped, or when the terminal is closed. Open a new terminal (if necessary), change to your pmi directory, and repeat steps 4 and 6.