Part 0 · Orientation · Module 00

Setup: Python 3.14 with Pixi

Before you can learn to program, you need a place to run programs. In this module you will learn how this course works, install Pixi, use it to get Python 3.14, and run your very first script. Every professional Python developer does this same setup, so nothing here is "just for beginners".

⏱ ~1 hourPrerequisites: none, just a computer and curiosity

How to use this course

Welcome! This course is designed for active learning. Research on learning is very clear on one point: you remember what you do far better than what you only read. So every page asks you to do something every few minutes. Here is the rhythm each module follows:

  1. Read a short explanation of one idea. Every new term is defined the first time it appears.
  2. Run the example. Code boxes with a Run button execute real Python 3.14 right in your browser (using a technology called Pyodide, which is CPython compiled to run inside a web page). You can edit the code and run it again. Breaking things is encouraged; you cannot damage anything.
  3. Predict before you run. Boxes marked "Predict the output" ask you to type what you think the program will print, then compare with reality. Wrong guesses are the most valuable moments in learning, because they show you exactly where your mental model differs from how Python really works.
  4. Exercise. In the Practice section you write code that is checked automatically by tests. A test is a small piece of code that checks whether your code behaves correctly.
  5. Quiz. A short quiz at the end of every module checks your understanding. Each answer comes with an explanation, so read them even when you are right.
  6. Mini-project. A small program you build on your own computer with Pixi, with a checklist of acceptance criteria (the conditions that mean "done").
  7. Part project. Each part of the course ends with a larger graded project that combines everything from that part. You start it with pixi run start p01 and grade it with pixi run grade p01 (you will set this up below).

Your progress is saved in your browser

Quiz scores, exercise results, checklists, and "Mark complete" buttons are saved in your browser's local storage. That means there is no account and no server; your data stays on your computer. It also means that if you switch browsers or clear your browser data, the progress is gone. To keep a backup, use the Export progress button on the home page; it downloads a small JSON file. Import progress on the same page loads it back, for example on another computer.

The notes box

At the bottom of every page there is a My notes box. Use it! Write what you learned in your own words, what confused you, and questions to come back to. Explaining an idea in your own words is one of the most effective ways to learn it. Notes are saved in the browser too and are included in the export.

Try your first runnable cell now. Press Run. Then change the text between the quotes and run it again.

The second line looks a bit mysterious right now. That is fine: you will understand every part of it by the end of Part 1. For now, notice that it reports a version starting with 3.14.

Package managers and environments

The browser cells are great for experiments, but real programs live in files on your computer. To run them you need Python installed. Before installing anything, let us understand two words you will hear constantly.

What is a package?

A package is a bundle of code someone else wrote so that you do not have to. Python itself comes with a big standard library (math, dates, files, and much more), but there are hundreds of thousands of extra packages: numpy for numbers, pandas for tables, pytest for testing. Even Python itself is distributed as a package.

What is a package manager?

A package manager is a program that downloads packages, installs them in the right place, and makes sure the versions fit together. Packages depend on other packages (these are called dependencies), and those depend on yet others. Working out a set of versions that are all compatible is called dependency resolution, and it is a hard problem that you want a tool to solve for you.

What is an environment?

An environment is a folder containing one particular Python interpreter plus one particular set of packages. Why not just install everything once, globally? Because projects disagree. Your data project might need pandas 2 while an old script needs pandas 1. If both share one installation, upgrading for one breaks the other. With one environment per project, each project gets exactly what it needs and nothing leaks between them.

budget-app/ pixi.toml (what I need) pixi.lock (exact versions) .pixi/envs/default/ python 3.14, pandas 2.3 old-script/ pixi.toml pixi.lock .pixi/envs/default/ python 3.12, pandas 1.5
Each project folder carries its own manifest, lockfile, and environment. They never interfere.

Why Pixi?

This course uses Pixi as its one and only tool for installing Python, installing packages, and running code. Pixi gives you:

conda-forge

Packages come from conda-forge, a huge community-maintained collection of pre-built packages, including Python itself and libraries written in C, C++, Fortran, and Rust. No compilers needed.

Per-project environments

Every project folder gets its own environment in a hidden .pixi/ folder. Delete the folder and it is gone; nothing else on your system changes.

Lockfiles

pixi.lock records the exact version of every package. Anyone who clones your project gets the identical environment: "it works on my machine" becomes "it works on every machine".

Tasks

Named commands such as pixi run test or pixi run serve live in pixi.toml, so you never have to remember long command lines.

Remember: a package manager installs code; an environment is an isolated folder of interpreter plus packages; Pixi gives each project its own environment, locked to exact versions.

Installing Pixi

You will type commands into a terminal (also called a shell or command line): a text window where you type a command, press Enter, and the computer prints a response. On macOS open the Terminal app; on Linux open your terminal emulator; on Windows open PowerShell from the Start menu. In this course, lines in a box labelled "Terminal" are commands you type.

curl -fsSL https://pixi.sh/install.sh | bash

curl downloads the installer script and | bash (a "pipe") hands it to the shell to run. It installs Pixi into ~/.pixi/bin and adds that folder to your PATH, the list of folders your shell searches for programs.

powershell -ExecutionPolicy Bypass -c "irm -useb https://pixi.sh/install.ps1 | iex"

irm (Invoke-RestMethod) downloads the installer and iex (Invoke-Expression) runs it. -ExecutionPolicy Bypass allows this one script to run.

Close the terminal and open a new one so it picks up the new PATH. Then check that it worked:

pixi --version

You should see something like pixi 0.x.y. If instead you see "command not found", the new terminal did not pick up the PATH change yet: open another fresh terminal, or log out and back in.

Your first Pixi workspace

A workspace is a project folder that Pixi manages. Let us make one called hello.

pixi init hello
cd hello
pixi add python=3.14

Line by line: pixi init hello creates a folder hello containing a starter pixi.toml. cd hello ("change directory") moves your terminal into that folder. pixi add python=3.14 asks Pixi to add Python 3.14 as a dependency; Pixi resolves versions, downloads Python from conda-forge, creates the environment, and writes the lockfile. The first time takes a minute; after that Pixi reuses its download cache.

Anatomy of pixi.toml

pixi.toml is the workspace manifest: a file that declares what the project needs. It is written in TOML ("Tom's Obvious Minimal Language"), a simple format made of [tables] (section headers in square brackets) and key = value lines. After the commands above it looks like this:

[workspace]
authors = ["Ada Lovelace <ada@example.com>"]
channels = ["conda-forge"]
name = "hello"
platforms = ["osx-arm64"]
version = "0.1.0"

[tasks]

[dependencies]
python = "3.14.*"

Files Pixi created

Running Python

pixi run python --version
pixi run python -c "print('hi from 3.14')"

pixi run means "run this command inside the workspace's environment". If the environment is missing or out of date, Pixi fixes that first. You can also open a shell where the environment is activated, so plain commands use it, and leave it with exit:

pixi shell
python --version     # inside pixi shell, this is the workspace's Python
exit

Tasks

Add a task so that one short word runs a longer command:

pixi task add hello "python hello.py"
pixi run hello

This adds hello = "python hello.py" under [tasks]. (It fails until you create hello.py; we do that in a moment.)

Global tools

Some programs are tools you want everywhere, not dependencies of one project. pixi global install installs a tool into its own private environment and puts its command on your PATH:

pixi global install git
pixi global list

Test your understanding of the manifest. The cell below parses a pixi.toml with Python's built-in tomllib module and prints what Pixi would see. Predict the last line first.

Remember: pixi init creates a workspace, pixi add adds dependencies, pixi run runs commands in the environment, pixi.lock pins exact versions, and .pixi/ is disposable.

Getting this course on your computer

This course is itself a Pixi workspace. You get a copy with git, the version-control tool professionals use to track changes to code. Cloning means downloading a full copy of a repository (a project tracked by git).

git clone https://github.com/millsks/python-practicum.git
cd python-practicum
pixi install

pixi install builds the environment from the lockfile without running anything. It installs Python 3.14 and every library the course uses (numpy, pandas, pytest, and more), so expect it to take a few minutes the first time.

The course helpers

CommandWhat it does
pixi run serveServes this website locally at http://127.0.0.1:8000 and opens your browser. Press Ctrl+C in the terminal to stop it.
pixi run projectsLists every graded project and whether you have started it.
pixi run start p01Copies Project 1's starter code into work/, where you write your solution.
pixi run grade p01Runs the project's tests against your code in work/ and reports which pass.

The Python 3.14 REPL

A REPL (Read–Eval–Print Loop) is an interactive Python prompt. It reads what you type, evaluates it, prints the result, and loops back for more. It is the fastest way to try a small idea. Start it from inside any workspace:

pixi run python

You will see a version banner and the prompt >>>. Type an expression and press Enter:

>>> 2 + 3
5
>>> "Py" * 3
'PyPyPy'
>>> for n in range(3):
...     print(n)
...
0
1
2

The ... prompt means Python is waiting for more lines of a multi-line statement. Press Enter on an empty line to finish it.

Handy REPL features

The browser cells behave much like a script rather than a REPL: only what you print is shown. Try help here:

An editor and your first script

The REPL forgets everything when you exit. Real programs are saved in scripts: plain text files ending in .py. You write them in a code editor, a text editor that understands code (colors, autocompletion, error underlines).

VS Code setup

  1. Install Visual Studio Code (free) and, from its Extensions panel, the Python extension by Microsoft.
  2. Open your workspace folder: File → Open Folder… and choose hello.
  3. Open the Command Palette (Ctrl/Cmd+Shift+P), run Python: Select Interpreter, and choose the one inside .pixi/envs/default (on macOS/Linux .pixi/envs/default/bin/python; on Windows .pixi\envs\default\python.exe). Now the editor's autocompletion and error checks use exactly the Python that pixi run uses.

Write and run hello.py

Create a file named hello.py in the hello folder with this content:

# My first Python script.
name = "world"
print(f"Hello, {name}!")
print("Python is adding:", 2 + 2)
pixi run python hello.py
pixi run hello        # the task you added earlier

Python reads the file top to bottom and runs each line in order. Lines starting with # are comments: notes for humans that Python ignores. Run the same script here and compare:

Reading error messages

Every programmer, from day one to year thirty, sees error messages every day. An error is not a sign that you are bad at this; it is Python telling you precisely what confused it. Learning to read errors calmly is the single most useful beginner skill.

When something goes wrong, Python prints a traceback: a report of where the program was when the error happened. Read it from the bottom up.

Traceback (most recent call last):
  File "hello.py", line 3, in <module>
    print(f"Hello, {nme}!")
                    ^^^
NameError: name 'nme' is not defined. Did you mean: 'name'?
  1. The last line is the most important: the exception type (NameError) and a message. Python even suggests a fix: did you mean name?
  2. The lines above it show the file, the line number (line 3), the line of code, and carets (^^^) pointing at the exact problem.
  3. "most recent call last" means the deepest point of the program is at the bottom, closest to the error message.
ErrorUsually means
SyntaxErrorThe code is not valid Python: a missing quote, bracket, or colon. Python refuses to run any of the file.
NameErrorYou used a name that was never assigned, often a typo.
TypeErrorAn operation got the wrong kind of value, such as "age " + 5.
IndentationErrorThe spaces at the start of a line do not line up.

Run this broken cell, read the traceback bottom-up, and fix it:

Remember: read tracebacks from the bottom; the last line names the problem, the lines above say where.

A peek at Python 3.15

Python releases a new version every October. While 3.14 is current, 3.15 is in development, and you can try it without changing any project. pixi exec creates a temporary environment, runs one command in it, and throws the environment away:

pixi exec --spec "python=3.15" python

Practice

Each exercise is checked by tests when you press Run. Read the test messages: they tell you what to fix.

Print exactly Hello, Pixi! (capital H and P, a comma, a space, and an exclamation mark). Computers are literal: one wrong character and the test fails.

Hint

Everything between the quotes is printed as-is. Check capitals and punctuation.

Show solution
print("Hello, Pixi!")

Print exactly three lines, in this order: Name: Ada, Learning: Python 3.14, and Tool: Pixi. Use one print per line.

Hint

Each print(...) call ends with a new line.

Show solution
print("Name: Ada")
print("Learning: Python 3.14")
print("Tool: Pixi")

This program has two bugs. Run it, read the traceback from the bottom, fix the first error, then run it again to find the second. When fixed it prints Total: 10.

Hint

Python reports the SyntaxError (a missing closing parenthesis) first, because it checks the whole file before running anything. Then look at the spelling of pears.

Show solution
apples = 4
pears = 6
total = apples + pears
print("Total:", total)

Store the text of a valid pixi.toml in the variable manifest_text. It must have a [workspace] table with name = "practice" and channels = ["conda-forge"]; a [dependencies] table with python = "3.14.*"; and a [tasks] table with a task named hello that runs python hello.py. The tests parse it with tomllib, just like Pixi would.

Hint

Every value goes under its table header. Strings need double quotes and lists use square brackets: channels = ["conda-forge"].

Show solution
manifest_text = """
[workspace]
name = "practice"
channels = ["conda-forge"]
platforms = ["linux-64", "osx-arm64", "win-64"]

[dependencies]
python = "3.14.*"

[tasks]
hello = "python hello.py"
"""

Mini-project: your practice workspace

Mini-projectSet up a practice workspace

You will use this workspace for every mini-project in Part 1, so it is worth setting up carefully. Work in a folder outside the course repository, for example in your home directory.

Steps

  1. pixi init practice, then cd practice.
  2. pixi add python=3.14. Open pixi.toml and find the new line.
  3. Create hello.py that prints a greeting and the Python version:
    import sys
    
    print("Hello from my practice workspace!")
    print("Python", sys.version.split()[0])
  4. pixi task add hello "python hello.py", then pixi run hello.
  5. Open the folder in your editor and select the .pixi/envs/default interpreter.
  6. Start the REPL with pixi run python, try help(print), and leave with exit.

Acceptance criteria

  • pixi --version prints a version number
  • practice/pixi.toml has python = "3.14.*" under [dependencies]
  • pixi.lock and .pixi/ exist in the workspace
  • pixi run hello prints your greeting and a version starting with 3.14
  • Your editor uses the interpreter in .pixi/envs/default
  • The course repository is cloned and pixi run serve opens this site locally
  • You ran pixi run projects and saw the list of projects

Stretch goals

  • Add a second task, repl = "python", and start the REPL with pixi run repl.
  • Run pixi exec --spec "python=3.15" python --version to meet the next version.
  • Run pixi list and count how many packages Python 3.14 brought with it.

Quiz

Recap

Going further