Appendix A: Installation and Setup

This appendix explains how to install everything the book uses, how to configure your working environment, and how to resolve the issues that most often arise. If you want to get started immediately, the short version is: install Python, install Visual Studio Code, create a virtual environment, and install the companion packages with pip. If you are not ready to install anything locally yet, every chapter’s exercises can also be run directly in your web browser in the interactive playground.

Software installers and websites update their appearance over time, so this appendix describes each step in clear terms. The essential configuration choices remain consistent across versions.

What you need

Table 1.1: The software used in this book
Software What it is Required?
Python (3.10+) The programming language and computation engine Yes
VS Code Code editor with integrated terminal, plot viewer, and notebook support Yes (or Positron)
Positron Modern data science IDE by Posit, designed for Python and R Optional
Quarto Authoring tool that compiles research code into papers, books, and slides Yes
Scientific packages Libraries (pandas, seaborn, scipy, etc.) installed via pip Yes
data2thesis Companion package containing all Graduate Wellbeing Study datasets Yes

All of these tools are free and open source. Python should be installed first so that editors and tools can discover your Python interpreter automatically.

Installing Python

Python is downloaded from the official Python Software Foundation website at python.org/downloads. Always download the latest stable release (version 3.10 or newer; 3.12 is recommended).

Windows

  1. On python.org, download the Windows installer (64-bit).
  2. Run the installer. On the very first screen, make sure to check the box: “Add python.exe to PATH”. This is essential: it enables your terminal and code editor to find Python.
  3. Click Install Now. If prompted with “Disable path length limit” at the end of the installation, click it to avoid Windows file-path truncation issues.

macOS

  1. On python.org, download the macOS 64-bit universal installer (.pkg).

  2. Run the package installer and accept the standard defaults.

  3. After installation completes, navigate to your Applications folder, open the Python 3.x folder, and double-click Install Certificates.command to ensure secure network connections (SSL) function properly when downloading datasets and packages.

  4. Alternatively, if you use Homebrew, you can install Python directly from Terminal:

    brew install python

Linux

Python comes pre-installed on most modern Linux distributions. On Debian/Ubuntu distributions, ensure the development packages and package manager are installed:

sudo apt update
sudo apt install python3 python3-pip python3-venv

Checking the installation

Open your system terminal (Command Prompt or PowerShell on Windows; Terminal on macOS and Linux) and type:

python --version

If it prints Python 3.12.x (or any version 3.10+), Python is installed and accessible.

Installing VS Code

  1. Download Visual Studio Code from code.visualstudio.com for your operating system.
  2. Install the application using default settings. On Windows, check the boxes to add “Open with Code” to the context menu.
  3. Open VS Code. On the left sidebar, click the Extensions icon (four square blocks, or press Ctrl+Shift+X / Cmd+Shift+X).
  4. Search for and install:
    • Python (by Microsoft)
    • Jupyter (by Microsoft)
    • Quarto (by Posit PBC)

Positron: A Dedicated Data Science Alternative

Positron (positron.posit.co) is a specialized code editor built by Posit for scientific data analysis in Python and R. It provides dedicated panes for Variables, DataFrames, and Plots out of the box. Everything taught in this book works identically in VS Code and Positron.

Managing projects with virtual environments

In empirical research, package versions evolve. To prevent package updates from inadvertently altering your thesis calculations months later, create a virtual environment for your research project. A virtual environment is an isolated directory containing its own Python interpreter and set of installed libraries.

In your research project folder:

# 1. Create a virtual environment named .venv
python -m venv .venv

# 2. Activate the virtual environment
# Windows (PowerShell):
.venv\Scripts\Activate.ps1
# Windows (Command Prompt):
.venv\Scripts\activate.bat
# macOS / Linux:
source .venv/bin/activate

When activated, (.venv) appears at the start of your terminal command line. In VS Code, press Ctrl+Shift+P (or Cmd+Shift+P), type Python: Select Interpreter, and choose the interpreter inside your .venv directory.

Installing the book’s packages

Scientific libraries are installed using Python’s package manager, pip. Each chapter in the book uses specific packages; Table 1.2 summarizes the primary libraries used across chapters.

Table 1.2: Python packages used across book chapters
Chapters Libraries
1–3 pandas, numpy, openpyxl, pyreadstat
4 matplotlib, seaborn
5–7 scipy, statsmodels
8–10 statsmodels (OLS, GLM, MixedLM)
11–13 scikit-learn, xgboost
14 scikit-learn (K-Means, DBSCAN, GMM, PCA)
15 scikit-learn, torch (PyTorch)
16 statsmodels (ARIMA, seasonal decomposition)
17 quarto, shiny, matplotlib
18 requests, openai / ollama
19 pandas, statsmodels, seaborn

To install all required packages into your virtual environment in a single command, run:

pip install pandas numpy openpyxl pyreadstat matplotlib seaborn scipy statsmodels scikit-learn xgboost torch shiny requests

The student wellbeing data: the data2thesis package

The case-study data for Elaf’s research is bundled in the companion package data2thesis. You can install it directly via pip:

pip install data2thesis

Verify that the package and dataset load properly:

import data2thesis as dt

students = dt.load_students()
print(f"Loaded {students.shape[0]} students and {students.shape[1]} variables.")
Loaded 600 students and 14 variables.

All datasets are also available as direct CSV, Excel, and SPSS downloads on the book website.

Software versions used in this book

The analyses in this edition were executed with the following package versions:

Software Version
0 Python 3.12.15
1 pandas 3.1.0
2 numpy 2.5.4
3 scipy 1.18.1
4 statsmodels 0.15.0
5 scikit-learn 1.9.1
6 data2thesis 1.1.0

Common problems and solutions

'python' is not recognized as an internal or external command
Python was installed without checking “Add python.exe to PATH”. Re-run the Python Windows installer, select Modify, and check the PATH option, or add your Python installation folder (e.g., C:\Users\Username\AppData\Local\Programs\Python\Python312\) to your system Environment Variables.
ModuleNotFoundError: No module named '...'
The library is not installed in the currently active Python environment, or VS Code is pointing to a different Python interpreter. Open the VS Code Command Palette (Ctrl+Shift+P), select Python: Select Interpreter, and choose your project’s .venv. Then run pip install <package-name>.
Execution of scripts is disabled on this system (Windows PowerShell)
PowerShell on Windows restricts script execution by default. Open PowerShell as Administrator and run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
This allows activating local virtual environment scripts.
File not found when loading datasets
In research scripts, always use relative paths starting from the project root (e.g., data/students.csv), or use the helper function dt.load_students(). Avoid absolute paths like C:\Users\Elaf\Desktop\data.csv, which fail when shared with supervisors or collaborators.
Restarting a clean session
If variables from earlier interactive runs are causing unexpected errors, restart the Python interactive kernel. In VS Code, click the Restart button at the top of the Interactive Window or notebook.