3.5 Installing Python and Setup
“The tools we use have a profound (and devious!) influence on our thinking habits, and, therefore, on our thinking abilities.”
— Edsger W. Dijkstra, EWD498, 1975
This chapter gets Python, the packages this book uses and an editor running on your computer. The guide comes first: follow the steps for your system in order. The explanations of why the setup looks the way it does come after the guide, and the options for power users are at the end.
You can start without installing anything. The university runs a server at jupyter.ju.se where Python runs in the browser, with everything this book uses already set up. Log in with your JU credentials.
Windows: One-Line Installer
Open PowerShell (search for “PowerShell” in the Start menu), paste this command and press Enter:
irm https://raw.githubusercontent.com/cenmir/python-dev-installer/main/download.ps1 | iexFollow the on-screen prompts until the installer finishes. It installs Git, VS Code, Python, the packages this book uses and marimo, and connects them. Then check that it works.
JU PC: Right-click the downloaded zip file → Properties → check “Unblock” → OK. Then extract and double-click setup.bat.
Private PC: Extract the zip file and double-click setup.bat.
What You Get

| Task | How |
|---|---|
| Launch Marimo | Right-click in a folder → “Open in Marimo”, or type m in terminal, or use Start Menu |
| Open folder in VS Code | Right-click on folder → “Open with VS Code” |
| Activate environment | Type activate default in PowerShell |
| Update packages | Double-click update.bat in C:\Users\username\marimo |
| Uninstall | Double-click uninstall.bat in C:\Users\username\marimo |
macOS and Linux
All steps are typed in a terminal. If you have not used one before, read Terminal Basics first.
Step 1: Install uv
Open a terminal and run:
curl -LsSf https://astral.sh/uv/install.sh | shStep 2: Install Python
Close the terminal and open a new one so that it finds uv. Then run:
uv python installStep 3: Create the Environment
Create the environment in your home folder:
mkdir -p ~/.venvs
uv venv ~/.venvs/defaultActivate it:
source ~/.venvs/default/bin/activateYour prompt should now begin with (default). Install the packages, which can take a while:
uv pip install marimo numpy sympy scipy matplotlib pandas pyqt6 pyqtgraph imageio ipykernelDo not put virtual environments on OneDrive or other cloud drives. Keep them in ~/.venvs on your local drive.
Step 4: Add Shortcuts
The commands below add three shortcuts to ~/.zshrc, the file your terminal reads when it starts. On Linux the file is usually ~/.bashrc; use that name instead.
Make python run Python 3 (macOS only):
echo 'alias python=python3' >> ~/.zshrc
source ~/.zshrcAdd activate, which activates the environment. Open the file:
nano ~/.zshrcAdd this line at the end:
alias activate="source ~/.venvs/default/bin/activate"Save and exit with Ctrl+X, Y, Enter, then reload the configuration:
source ~/.zshrcAdd startMarimo, which activates the environment and starts marimo in one step:
echo 'alias startMarimo="source ~/.venvs/default/bin/activate && echo \"venv: \$VIRTUAL_ENV\" && marimo --version && marimo edit"' >> ~/.zshrc
source ~/.zshrcThen check that it works.
Check That It Works
Open a terminal with the environment active (see below) and run:
python -c "import numpy; import sympy; import matplotlib; print('All packages working!')"If it prints “All packages working!”, your setup is complete. If it reports an import error, install the missing package with uv pip install package_name.
Everyday Use
Activate the Environment
Python only finds the packages when the environment is active. Activate it in every new terminal:
activate defaultWithout the installer, run the activation script directly:
. $env:USERPROFILE\.venvs\default\Scripts\Activate.ps1activateWithout the shortcut, run:
source ~/.venvs/default/bin/activateThe prompt then begins with (default).

The terminal inside VS Code activates the environment by itself once you have selected the interpreter.
Start Marimo
On Windows, right-click in a folder and choose “Open in Marimo”, or type m in a terminal. On macOS and Linux, change to the folder and run startMarimo:
cd ~/OneDrive/Programming
startMarimoMarimo opens in your browser with access to the files in that folder. Press Ctrl+C in the terminal to stop it.
Install and Update Packages
With the environment active, the commands are the same on every system. To install a new package:
uv pip install package_nameTo upgrade a package to its latest version, here marimo:
uv pip install --upgrade marimoTo list the installed packages and their versions:
uv pip listTo update Python itself:
uv python installWhere to Keep Your Files
Save your Python files and notebooks on OneDrive, so that they sync across devices and are backed up, for example:
~/OneDrive/Programming/
├── marimo_notebooks/
├── pyqt_projects/
└── exercises/
The environment stays in .venvs on your local drive. To go to your OneDrive folder:
cd ~/OneDriveOn macOS, OneDrive may instead be at:
cd ~/Library/CloudStorage/OneDrive-PersonalYou can find the exact path by dragging your OneDrive folder from Finder into the terminal window.
VS Code
Install VS Code
If you used the Windows installer, VS Code is already installed; skip to Select the Python Interpreter.
Download VS Code from code.visualstudio.com and install it. Open it, press Ctrl+Shift+X to open the Extensions panel, search for “Python”, and click Install on the extension published by Microsoft.
Select the Python Interpreter
Open any Python file or create a new one, then press Ctrl+Shift+P (or Cmd+Shift+P on macOS), type “Python: Select Interpreter” and press Enter.
If the default environment appears in the list, select it. Otherwise, click “Enter interpreter path…”, then “Find…”, and select:
C:\Users\yourusername\.venvs\default\Scripts\python.exe
Replace yourusername with your actual Windows username.
If the default environment appears in the list, select it. Otherwise, click “Enter interpreter path…”, then “Find…”, and select:
~/.venvs/default/bin/python
The selected interpreter is shown in the status bar at the bottom; click it to switch.
Run Python Scripts
F5 runs the current file in the debugger and Ctrl+F5 runs it without. PyQt applications and simulations should instead run in the terminal: open it with Ctrl+ö on Nordic keyboards or Ctrl+` on others, check that the prompt begins with (default), and run
python my_simulation.pyCtrl+C stops the script.
Jupyter Notebooks
Open a .ipynb file, or create one with Ctrl+Shift+P → “Create: New Jupyter Notebook”. When VS Code asks for a kernel, choose the interpreter in .venvs/default. The selected kernel is shown in the top-right corner of the notebook.
Troubleshooting
“uv is not recognized”
Close the terminal and open a new one. The PATH update takes effect only in new terminal sessions.
PowerShell execution policy error or script blocked
Run the commands in Configuring Windows for Development, then restart your terminal.
VS Code doesn’t find my interpreter
Click the Python version in the status bar, select “Enter interpreter path”, and select the Python executable in .venvs/default by hand (see Select the Python Interpreter).
Starting fresh
If your environment becomes corrupted, delete the .venvs/default folder and recreate it by repeating the installation steps.
How the Setup Works
The guide above tells you what to do. This section explains why.
Three Ways We Use Python
Interactive exploration happens in marimo notebooks, which suit symbolic computation and visualization and can be shared as HTML or Python files. Scripts are .py files written in VS Code, mainly for simulations such as real-time applications with PyQt. Jupyter notebooks, also edited in VS Code, display symbolic output well and work with quarto to produce PDF and HTML reports. All three use the same Python installation, managed by uv, and the same virtual environment.
Virtual Environments
When you install Python, you get a single global environment where all packages live together. This seems convenient until you encounter version conflicts. Suppose one project requires numpy 1.x while another needs numpy 2.x, or you want to try a new package without risking your working setup. With a single global environment, these situations lead to broken installations.
A virtual environment is an isolated Python installation with its own set of packages. Installing or upgrading a package in one environment does not affect any other, and an environment that becomes corrupted or cluttered can be deleted and created afresh. The environment folder contains a copy of the Python interpreter and a site-packages directory where installed packages live. When you activate an environment, commands like python and pip in that terminal refer to the environment, and the prompt starts with its name in parentheses, (default) for ours.
For this course we use a single shared environment called default that contains all the packages we need. It lives in a local folder, ~/.venvs/default on macOS/Linux or %UserProfile%\.venvs\default on Windows, and not inside a project folder. Project folders are often on cloud drives such as OneDrive, and a virtual environment contains thousands of small files, which cause sync problems, slow performance and take up cloud storage. If you later work on projects with conflicting requirements, you can create additional environments.
Packages, pip and uv
A package is code that someone has written and shared for use in other programs. Instead of implementing matrix operations from scratch, we import numpy; instead of writing plotting code, we import matplotlib. The Python Package Index (PyPI) hosts hundreds of thousands of packages.
The standard tool for installing packages is pip, which comes bundled with Python. Running pip install numpy downloads numpy from PyPI and installs it into the active environment, and pip install numpy==1.26.0 installs a specific version. Packages depend on other packages: installing matplotlib also installs numpy and pillow. If two packages require incompatible versions of a shared dependency, pip must find a combination that satisfies both, and separate environments keep such conflicts inside one project.
We use uv pip instead of plain pip because it does the same work faster. uv is written in Rust and is often 10 to 100 times faster than pip; it caches downloads, so repeated installations are nearly instantaneous. The syntax is the same, with uv in front: pip install numpy becomes uv pip install numpy. uv also installs and switches between Python versions.
Why Not Anaconda or the python.org Installer?
Anaconda bundles Python with hundreds of scientific packages, which sounds convenient but leads to bloated installations and version conflicts that are hard to resolve. The official Python installer works, but managing several Python versions and virtual environments with it needs additional tools. uv does both through short terminal commands. A typed command states exactly what it does, its error messages say what went wrong, and the same commands repeat the setup on another machine.
What the Windows Installer Does
Software
- Git: version control; the installer asks for your name and email to configure it
- VS Code: code editor, with the Python and Jupyter extensions pre-installed
- uv: fast Python package manager
- Python: the latest version, installed through uv
Environment
- Creates a virtual environment at
C:\Users\username\.venvs\default - Installs packages: numpy, sympy, scipy, matplotlib, marimo, imageio, pyqt6, pyqtgraph, pandas, ipykernel
- Configures VS Code to use the virtual environment automatically
Shortcuts and integration
- Adds
activate defaultcommand to quickly activate the environment - Adds
mcommand to launch Marimo from any terminal - Creates Start Menu shortcuts for Marimo
- Adds “Open in Marimo” to the right-click context menu
- Adds “Open with VS Code” to the right-click context menu
- Enables classic context menu on Windows 11 (removes “Show more options”)
- Configures Marimo to use dark mode by default
- Sets the PowerShell execution policy so that scripts can run
The Packages We Install
| Package | Description |
|---|---|
marimo |
Interactive notebook environment for Python, ideal for symbolic computation and visualization with interactivity |
numpy |
Numerical computing library providing arrays, linear algebra, and mathematical functions |
sympy |
Symbolic mathematics library for algebraic manipulation, calculus, and equation solving |
scipy |
Scientific computing library with optimization, integration, interpolation, and signal processing |
matplotlib |
Plotting library for creating static, animated, and interactive visualizations |
pandas |
Data analysis library for working with tabular data and time series |
pyqt6 |
GUI framework for building desktop applications with windows, buttons, and interactive elements |
pyqtgraph |
Fast plotting library built on PyQt, suitable for real-time data visualization in simulations |
imageio |
Library for reading and writing image and video data |
ipykernel |
Jupyter kernel that enables notebook support in VS Code |
Terminal Basics (macOS)
Opening the Terminal
Press Cmd+Space to open Spotlight, type “Terminal”, and press Enter. A window opens with a command prompt, which shows your username and current folder and ends with $ or %. To “run” a command, type it after the prompt and press Enter; the output appears below it.
The Home Folder and ~
Every user has a home folder for personal files, on macOS /Users/yourusername. The terminal uses ~ (tilde) as shorthand for this path, so ~/.venvs means /Users/yourusername/.venvs.
A new terminal starts in your home folder, and the prompt shows ~ to say so. Files and folders whose names start with a dot, like .venvs or .zshrc, are hidden in Finder by default; in the terminal, ls -alh lists them.
Essential Terminal Commands
| Command | Description | Example |
|---|---|---|
pwd |
Print working directory (where you are) | pwd → /Users/anna/Documents |
ls |
List files in current folder | ls |
ls -alh |
List all files (including hidden) with details | ls -alh |
cd |
Change directory | cd Documents |
cd ~ |
Go to home folder | cd ~ |
cd .. |
Go up one folder | cd .. |
mkdir |
Create a new folder | mkdir projects |
rm |
Remove a file | rm oldfile.py |
rm -r |
Remove a folder and its contents | rm -r oldfolder |
cp |
Copy a file | cp file.py backup.py |
mv |
Move or rename a file | mv old.py new.py |
Paths can be absolute (starting with / or ~) or relative (starting from your current location). For example, if you are in ~/Documents, typing cd projects takes you to ~/Documents/projects.
Editing Files with nano
nano is a simple text editor that runs in the terminal. To create or edit a file:
nano filename.txtThe file opens in the terminal, ready for editing. The bottom of the screen lists the available commands, where ^ means the Control key.
To save and exit:
- Press
Ctrl+X(exit) - Press
Y(yes, save changes) - Press
Enter(confirm filename)
If you made no changes, Ctrl+X exits immediately.
For Power Users
Nothing in this section is needed for the course.
Configuring Windows for Development
The Windows installer already sets the PowerShell execution policy and enables the classic context menu. The settings below are for manual installation and for the other defaults that get in the way of development. Open PowerShell as Administrator: right-click the Start button and choose “Terminal (Admin)”, or search for PowerShell and select “Run as administrator”. Run the commands below in this window, then restart your computer.
Allow PowerShell Scripts
Windows blocks PowerShell scripts by default, including the script that activates a virtual environment. Allow them for your user account:
Set-ExecutionPolicy Bypass -Scope CurrentUser -ForceUnblock Downloaded Files Automatically
Windows marks downloaded files as untrusted and then warns about or blocks them when you run an installer or script or extract a zip file. To stop Windows from marking future downloads:
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Attachments" -Name "SaveZoneInformation" -Value 1 -Type DWord -Force
New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Policies\Associations" -Name "DefaultFileTypeRisk" -Value 0x1808 -PropertyType DWord -Force 2>$nullTo unblock files you have already downloaded, navigate to the folder containing them and run:
Get-ChildItem -Recurse | Unblock-FileDisable SmartScreen
SmartScreen blocks executables that Microsoft has not seen before, which includes most development tools, Python packages with native components, and anything you compile yourself. To disable it:
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer" -Name "SmartScreenEnabled" -Value "Off" -ForceThese changes do not make your computer insecure. They make you, and not Microsoft, responsible for what you run. A developer who understands what they install is better protected than one who clicks through warnings without reading them.
Manual Installation on Windows
These steps do by hand what the installer does. Run Allow PowerShell Scripts first.
Install uv. Open cmd.exe from the Start menu and run:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"Install Python. Close cmd.exe and open a new one so that it finds uv. Then run:
uv python installCreate the environment. Open PowerShell and run:
mkdir $env:USERPROFILE\.venvs
uv venv $env:USERPROFILE\.venvs\defaultActivate it:
. $env:USERPROFILE\.venvs\default\Scripts\Activate.ps1If this fails with an error about execution policies, allow scripts for the current user and then run the activation command again:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUserYour prompt should now begin with (default). Install the packages:
uv pip install marimo numpy sympy scipy matplotlib pandas pyqt6 pyqtgraph imageio ipykernelAdd shortcuts. If you do not yet have a PowerShell profile script, create one:
New-Item -Path $PROFILE -ForceAdd the activate and startMarimo functions to the profile:
Add-Content $PROFILE 'function activate($name) { & "$env:USERPROFILE\.venvs\$name\Scripts\Activate.ps1" }'
Add-Content $PROFILE 'function startMarimo { & "$env:USERPROFILE\.venvs\default\Scripts\Activate.ps1"; Write-Host "venv: $env:VIRTUAL_ENV"; marimo --version; marimo edit }'Reload the profile:
. $PROFILENow activate default activates the environment in any terminal. To start marimo in a folder, open the folder in File Explorer, right-click and choose “Open in Terminal”, then run startMarimo.
Per-Project Environments
When a project needs its own isolated dependencies, copy init.bat from C:\Users\username\marimo into the project folder and double-click it. The script checks for uv, installs Python if needed, and creates a local .venv with all standard packages. VS Code detects the .venv folder and uses it as the Python interpreter.
WSL
Windows Subsystem for Linux (WSL) runs a full Linux environment inside Windows. It helps if you prefer Linux tools or want to follow Linux tutorials without modification.
To install WSL with Ubuntu (the default distribution), run in PowerShell as Administrator:
wsl --installWhen the installation completes, restart your computer. On the next boot, Ubuntu finishes setting up and asks you to create a username and password for the Linux environment.
To open WSL later, search for “Ubuntu” in the Start menu or type wsl in any terminal. You get a bash shell where Linux commands work natively. Inside it, follow the macOS and Linux steps; the environment then lives in the fast WSL filesystem and not on the Windows drive.
Your Windows files are under /mnt/c/Users/yourusername/, and OneDrive is typically at /mnt/c/Users/yourusername/OneDrive/, so your Python files can stay on OneDrive:
cd /mnt/c/Users/yourusername/OneDriveVS Code connects to WSL through the “WSL” extension. With the extension installed, open a folder in WSL by clicking the green remote indicator in the bottom-left corner and selecting “Connect to WSL”.