Computational Setup

Python, uv, and Code Editors

2026-08-27

Installation

  • Installation

  • Workspaces and Python Environment

  • Python Basics

Install Positron

Positron is a data science IDE for Python and R. It includes notebooks, variables, plots, terminals, and a project-based workflow.

Download Positron

Windows Computer

Install the latest Visual C++ Redistributable.

Python Programming

Python is a general-purpose programming language widely used for statistics, data science, machine learning, automation, and reproducible research.

Python

Tip

For this course, we will let uv manage Python versions, virtual environments, and package installation whenever possible.

Install uv

uv is a fast Python package and project manager. It can install Python, create virtual environments, and install packages from a pyproject.toml file.

uv

Install VS Code

Visual Studio Code is a general-purpose code editor with strong Python support through extensions.

Download VS Code

Recommended extensions:

  • Python
  • Jupyter
  • Quarto

Install VSCodium

VSCodium is an open-source build of VS Code with Microsoft telemetry disabled.

VSCodium

Recommended extensions:

  • Python
  • Jupyter
  • Quarto

Note

VSCodium uses the Open VSX extension registry by default, so extension names and availability can differ slightly from VS Code.

Workspaces and Python Environment

  • Installation

  • Workspaces and Python Environment

  • Python Basics

Workspaces

Workspaces allow you to create locations on your computer and set up a computing environment in one project folder.

A good workflow is:

  1. Create one folder for the course.
  2. Put pyproject.toml in that folder.
  3. Open the folder in Positron, VS Code, or VSCodium.
  4. Run uv sync once from that folder.
  5. Use uv run ... commands from that folder.

Course Project Files

Your course project folder should include a pyproject.toml.

A pyproject.toml file records project metadata and the Python packages required for the course.

Example structure:

course-folder/
├─ pyproject.toml
├─ lectures/
├─ data/
└─ scripts/

Class Packages

Replace your pyproject.toml with the class toml file.

Install Packages with uv

Open a terminal in the folder that contains pyproject.toml.

Then run:

uv sync

This command will:

  1. Read the package list in pyproject.toml.
  2. Create a project virtual environment in .venv.
  3. Install the required packages.
  4. Create or update uv.lock.

Check the uv Environment

Run Python inside the project environment:

uv run python

Try importing a package:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

Exit Python:

exit()

Course Python Packages

The course pyproject.toml includes packages for data analysis, visualization, statistical modeling, machine learning, and notebooks.

Core examples:

  • numpy
  • pandas
  • matplotlib
  • plotnine
  • scipy
  • statsmodels
  • scikit-learn
  • jupyter

Note

More packages may be added throughout the course if necessary.

Load Python Packages

You must import packages every new Python session.

Python Basics

  • Installation

  • Workspaces and Python Environment

  • Python Basics

Python as a calculator

Python can evaluate expressions in the console or in a code cell.

Try the following:

  1. \(4(4+2)/34\)
  2. \(6^3\)
  3. \(3-1\)
  4. \(4+4/3+45(32*34-54)\)
46535.333333333336

Python Functions

Python functions perform tasks on specific values.

Evaluate the following values in Python:

  1. \(\sqrt{3}\)
  2. \(e^3\)
  3. \(\ln(53)\)
  4. \(\log(324)\)
  5. \(\sin(3)\)
  6. \(\sin(3\pi)\)
3.6739403974420594e-16

Types of Data

  • Numeric: int, float
  • Character/text: str
  • Logical: bool
  • Missing: None, np.nan, or pd.NA

Evaluate the following code:

NoneType

Types of Objects

In Python, an object contains data and behavior. Common data objects include lists, arrays, dictionaries, and data frames.

Run this code and print the objects:

array([[ 1,  2,  3,  4,  5],
       [ 6,  7,  8,  9, 10],
       [11, 12, 13, 14, 15],
       [16, 17, 18, 19, 20]])

Data Frames

Data frames can be thought of as Python’s version of a data set.

Play around with a small data frame:

mpg cyl gear
0 21.0 6 4
1 21.0 6 4
2 22.8 4 4
3 21.4 6 3
4 18.7 8 3

Lists

A list stores multiple Python objects in order. The elements can be different types.

Try playing with this Python object:

[    mpg  cyl  gear
 0  21.0    6     4
 1  21.0    6     4
 2  22.8    4     4
 3  21.4    6     3
 4  18.7    8     3,
 [0, 0, 0, 0],
 array([[1., 0., 0.],
        [0., 1., 0.],
        [0., 0., 1.]])]

Comparing Numbers

You can compare two numbers or objects. The result is a logical output: True or False.

Comparing Numbers Operators

Operator Description
> Greater Than
< Less Than
>= Greater than or equal
<= Less than or equal
== Equals
!= Not Equals

Dictionaries: Key-Value Objects

A dictionary stores values by name.

[0, 0, 0, 0]

Resources in Programming