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:
Open a Windows PowerShell terminal.
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'.Inside the
pmidirectory, 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)
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.
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.)
Start JupyterLab:
jupyter-lab # Starts JupyterLab.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.
Open the Terminal app.
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'.Inside the
pmidirectory, 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)
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.
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.)
Start JupyterLab:
jupyter-lab # Starts JupyterLab.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.
.\.venv\Scripts\Activate.ps1 fails because it is not allowed to execute scripts.
Before executing Activate.ps1, run this to allow the execution of scripts:
Set-ExecutionPolicy Unrestricted -Scope CurrentUserIf 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.
Program 'pip.exe' failed to run: This program is blocked by group policy.
Try running python -m pip instead.
Program 'jupyter-lab.exe' failed to run: This program is blocked by group policy.
Try running python -m jupyterlab instead.
.\.venv\Scripts\Activate.ps1 just opens the file in Notepad.
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
Server Connection Error
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.