Getting started with Python#
Learning objectives
By the end of this lab, you will be able to:
Explain what the Python interpreter is and why it must be installed
Install uv and use it to install Python
Explain what a virtual environment is and how uv creates one for each project
Initialise a Python project with
uv initInstall and configure VSCodium for Python development
Add a Python library with
uv addRun scripts and interactive Python sessions with
uv run
Part 1: Install uv and Python#
What does “installing Python” mean?#
Python is a programming language: a set of rules for writing instructions that a computer can follow. A file with Python code is plain text, so your computer cannot run it on its own. It needs a program called the Python interpreter, which reads your file and carries out its instructions one line at a time. “Installing Python” means putting this interpreter on your computer.
There are several ways to do it. You can download an installer from python.org on Windows and macOS, or use the package manager of your Linux distribution. Each operating system follows a different procedure, and things get harder when you need two versions of Python on the same machine.
In this course we use a single method for everyone: a small program called uv. It works the same way on Windows, macOS, and Linux, so every student types the same commands. uv downloads Python for you, keeps several Python versions side by side, and switches between them when a project needs it. It also does three other jobs that you will meet later in this lab:
it creates a project (Part 2);
it installs libraries, keeping the libraries of each project separate from the others (Part 4);
it runs your code (Part 2 and Part 3).
What is the shell?#
Before installing anything, you need a way to give commands to your computer by typing them. This is the job of the shell (also called terminal, command line, or CLI). You type a command, press Enter, and read the answer that appears below. The window is called the terminal; the program inside it that reads your commands is the shell. On Windows the shell is PowerShell, while on macOS and Linux it is usually zsh or bash. The next section shows how to open the terminal on each system.
Why use the shell?
The shell allows you to install software, run programs, navigate files, and execute Python code directly.
Opening the shell#
Open the Windows menu
Type “powershell” in the search bar
Select Windows PowerShell
Press
Cmd + Spaceto open SpotlightType “terminal”
Press Enter
Search for “terminal” in the applications menu
On Ubuntu, Linux Mint, and KDE Plasma,
Ctrl + Alt + Topens it directly
Installing uv#
After you open the shell, copy the command for your operating system, paste it in the shell, and press Enter. The command downloads uv from the Internet and installs it:
powershell -ExecutionPolicy ByPass -c “irm https://astral.sh/uv/install.ps1 | iex”
curl -LsSf https://astral.sh/uv/install.sh | sh
curl -LsSf https://astral.sh/uv/install.sh | sh
When the installer finishes, close and reopen the shell before checking that uv is available:
uv --version
The shell answers with a line such as uv 0.9.8 (the number depends on the version installed). If it says that uv is not recognised or not found, close the shell, open it again, and retry.
Installing Python#
Now ask uv to download and install the current Python version:
uv python install
You should see a short message with the version being downloaded, followed by a line such as Installed Python 3.14.0. From now on uv knows where this interpreter is, and you do not need a separate installer.
Part 2: VSCodium setup#
A code editor is a program for writing code. It works like a word processor built for programs: it colours the parts of your code, suggests words while you type, and lets you run scripts from inside the window.
Visual Studio Code (VS Code) is the most used code editor today. Its source code is open, but the copy that Microsoft ships adds telemetry (data about your usage sent to Microsoft) and built-in AI helpers. In this course we use VSCodium, a community build of the same source code with telemetry and AI features switched off. Everything else, from the menus to the shortcuts, is the same, so any VS Code guide applies to VSCodium as well.
Installing VSCodium#
In the shell, type
$env:PROCESSOR_ARCHITECTUREand press Enter. The answer isAMD64orARM64Go to the latest VSCodium release and download the user installer for your PC:
VSCodiumUserSetup-x64-<version>.exeforAMD64,VSCodiumUserSetup-arm64-<version>.exeforARM64Open the downloaded file and install following the default options.
In the shell, type
uname -mand press Enter. The answer isarm64on Apple silicon Macs andx86_64on Intel MacsGo to the latest VSCodium release and download the
.dmgfile for your Mac:VSCodium.arm64.<version>.dmgforarm64,VSCodium.x64.<version>.dmgforx86_64Open the
.dmgfile and drag VSCodium into the Applications folder
Go to vscodium.com/install
Follow the instructions for your distribution
Installing the Python extension#
An extension adds support for a specific language or task to the editor. VSCodium downloads extensions from Open VSX, a registry independent from Microsoft.
Open VSCodium
Click the Extensions icon on the left sidebar (or press
Ctrl+Shift+X/Cmd+Shift+X)Search for “Python”
Install the extension published by ms-python

Your first Python script#
Working with folders (important!)
In programming, it’s essential to organize your work in folders (also called directories). This helps you:
Keep your files organized
Manage projects more easily
Prepare for version control with Git/GitHub
Follow professional development practices
Always open VSCodium in a folder, not just individual files!
Step 1: Create a dedicated folder for your Python work#
Create a folder named python_laboratory somewhere easy to find, such as Documents or Desktop.
One folder per project
You will use this folder for all the exercises in this first lab. As the course progresses, I recommend creating a separate folder for each lab or project (e.g. lab-01, lab-02, etc.). Keeping different projects in different folders avoids mixing files and, later on, allows each project to have its own isolated Python environment with only the packages it needs.
Step 2: Open the folder in VSCodium#
Open VSCodium
Select File → Open Folder… (or File → Open… on macOS)
Navigate to your
python_laboratoryfolder and select itClick Select Folder (or Open)
You should now see your folder name in the sidebar (Explorer panel).
Step 3: Initialise the project#
In this course a project is a folder that holds your code plus a small file describing what the code needs to run: which Python version and which libraries. uv reads that file whenever it runs your code, so anyone who opens the folder gets the same setup.
After you open the folder in VSCodium, select Terminal → New Terminal. This opens a shell at the bottom of the window, already placed inside python_laboratory. Type this command and press Enter:
uv init --bare
The command prints nothing and creates one file, pyproject.toml, which stores the project’s settings and the list of its libraries. You can see it appear in the Explorer panel on the left.
```{admonition} Run uv init inside the project folder
:class: warning
Before you run uv init --bare, check that the shell is inside python_laboratory: the shell prompt shows the current folder. A new shell usually opens in your home folder. If you run the command there, uv treats your whole home folder as one project, and every folder inside it becomes part of that project.
If this already happened, delete pyproject.toml from your home folder. Then run uv init --bare in each project folder that has no pyproject.toml.
#### Step 4: Create your first Python file
1. In VSCodium, look at the left sidebar and make sure the **Explorer** tab is selected (folder icon)
2. You should see your `python_laboratory` folder name at the top
3. Click on the **New File...** icon (it looks like a page with a plus sign, near the folder name)

4. Type `hello.py` as the filename and press Enter
VSCodium will create the file and open it in the editor.
#### Step 5: Write and run your code
1. In the `hello.py` file, write this code:
```python
print("Hello, World!")
If the integrated terminal is closed, select Terminal → New Terminal
Run the script through uv:
uv run hello.py
You should see this output in the terminal at the bottom:
Hello, World!
Part 3: Interactive Python basics#
Python interactive mode#
You can also use Python like a calculator by starting its interactive mode from the integrated terminal:
uv run python
You’ll see the Python prompt:
>>>
Now you can type Python commands and see immediate results.
Interactive code blocks
The code blocks below are executable! You can run them directly in your browser:
Click the rocket icon in the top-right corner of the page
Select Live Code
Click Restart to initialize the kernel
Wait for the kernel to start (this may take a few moments)
Click Run on any code block to execute it
This feature uses Thebe to connect to a live Python kernel, allowing you to experiment with the code without leaving your browser.
Try it: Basic arithmetic#
# Addition
print(5 + 3)
8
# Multiplication
print(7 * 6)
42
# Division
print(20 / 4)
5.0
# Exponentiation
print(2 ** 8)
256
Variables#
Variables store data that you can reuse:
# Create a variable
paradox = "Zeno's paradox"
print(paradox)
Zeno's paradox
# Variables with numbers
distance = 100
print(distance)
100
More on variables
In Lab 02, you’ll learn about variable naming rules, data types, operators, and much more!
The print() Function#
The print() function displays output to the screen:
print("You can print text")
print(42)
print("You can print", "multiple", "things", "separated", "by", "commas")
You can print text
42
You can print multiple things separated by commas
# Print with variables
name = "Descartes"
school = "Rationalism"
print(name, "belongs to", school)
Descartes belongs to Rationalism
Part 4: Adding Python libraries#
What are libraries?#
Libraries (also called packages or modules) are collections of pre-written code that extend Python’s capabilities. Some libraries are built-in (like math), while others need to be installed. Installing a library means downloading its files and placing them where the Python interpreter can find them.
What is a virtual environment?#
Suppose every project on your computer shared the same Python installation. Every library you install would end up in the same place. Sooner or later two projects would need two different versions of the same library, and only one could be installed. It would also be hard to tell which libraries a given project uses.
A virtual environment solves this. It is a folder, usually named .venv, that sits inside the project and holds a private copy of the Python interpreter together with the libraries of that project only. Each project gets its own environment, so projects do not interfere with each other.
Creating an environment without uv
Python includes a module called venv that creates virtual environments. Without uv, you would create one, “activate” it so that the shell uses that interpreter, and then install libraries with pip, the installer that comes with Python:
python -m venv .venv .venv\Scripts\Activate.ps1 pip install python-dateutil
python3 -m venv .venv source .venv/bin/activate pip install python-dateutil
We will not do this in the course. uv creates and uses the environment on its own, with no activation step, and writes down the libraries it installed so that the project can be rebuilt on any other computer. See the venv documentation if you want to know more.
Adding a library#
Add python-dateutil, which is a library for working with dates, to the project:
uv add python-dateutil
Three things happen. uv creates the .venv folder, which is the virtual environment of this project, and installs the library inside it. It adds python-dateutil to the list in pyproject.toml. It also writes uv.lock, a file that records the exact version of every library installed. Because uv manages these files when you use uv add and uv run, you do not need to activate the environment yourself.
Now you can use it to parse and work with dates:
from dateutil import parser
# Parse dates written in natural language
date1 = parser.parse("15 March 1789")
date2 = parser.parse("October 31, 1517")
print("French Revolution (Estates-General):", date1)
print("95 Theses:", date2)
French Revolution (Estates-General): 1789-03-15 00:00:00
95 Theses: 1517-10-31 00:00:00
Save this code in a file called dates.py inside python_laboratory and run it with uv run dates.py. The output shows both dates in the same standard format, whatever the way they were written.
Summary#
In this lab, you learned how to:
Explain what the Python interpreter is
Install uv and Python
Use the command line shell
Set up VSCodium for Python development
Initialise a project with
uv initExplain what a virtual environment is
Add project dependencies with
uv addRun scripts and interactive Python with
uv runUse variables and
print()
Next lab
In Lab 02, you’ll dive deeper into Python basics: operators, data type conversions, and more advanced string operations.