Lecture 1 Introduction to SE for Media

Slides

Python Setup

uv

At it’s simplest level uv is a package manager for python. It replaces a number of different tools in one simple to use tool.

It is already installed and pathed in the labs so users can use it directly in the terminal or in IDE’s such as PyCharm.

To get started we can use the following command.

uv init MyProject
Initialized project `myproject` at `/home/jmacey/MyProject`

We can now change into the folder and see what uv has created.

MyProject

cd MyProject
➜  MyProject git:(main) ✗ ls -a
.git            .python-version pyproject.toml
.gitignore      main.py         README.md

As you can see uv has setup a full git version control project as well as created a pyproject.toml file and main.py file.

Running the project

We can run the file by using.

uv run main.py
Using CPython 3.9.21 interpreter at: /usr/bin/python3.9
Creating virtual environment at: .venv
Hello from myproject!

As you can see here uv has chosen the default python installed on the system (3.9) which is quite old.

Introduction to uv

uv python

The uv python command lets us manage python versions. We can see what is available to download by running.

uv python list
cpython-3.14.0b3-linux-x86_64-gnu                 <download available>
cpython-3.14.0b3+freethreaded-linux-x86_64-gnu    <download available>
cpython-3.13.5-linux-x86_64-gnu                   <download available>
cpython-3.13.5+freethreaded-linux-x86_64-gnu      <download available>
cpython-3.12.11-linux-x86_64-gnu                  <download available>
cpython-3.11.13-linux-x86_64-gnu                  <download available>
cpython-3.10.18-linux-x86_64-gnu                  <download available>
cpython-3.9.23-linux-x86_64-gnu                   <download available>
cpython-3.9.21-linux-x86_64-gnu                   /usr/bin/python3.9
cpython-3.9.21-linux-x86_64-gnu                   /usr/bin/python3 -> python3.9
cpython-3.9.21-linux-x86_64-gnu                   /usr/bin/python -> ./python3
cpython-3.8.20-linux-x86_64-gnu                   <download available>
pypy-3.11.11-linux-x86_64-gnu                     <download available>
pypy-3.10.16-linux-x86_64-gnu                     <download available>
pypy-3.9.19-linux-x86_64-gnu                      <download available>
pypy-3.8.16-linux-x86_64-gnu                      <download available>
graalpy-3.11.0-linux-x86_64-gnu                   <download available>
graalpy-3.10.0-linux-x86_64-gnu                   <download available>
graalpy-3.8.5-linux-x86_64-gnu                    <download available>

Installing a new version

As you can see there are many versions available to download and the list is curated to work with recent / supported versions of python. To install a more recent version we can run.

uv python install 3.13
Installed Python 3.13.5 in 1.06s
 + cpython-3.13.5-linux-x86_64-gnu

Note version choice is important when working with the DCC tools, so check which version they use if you are writing support tools etc. If we create a root level .python-version file uv will use this. This is now done as part of the .zsh installer.

A new project

When we now create a new project the most recent version of python will be used.

uv init Project2
Initialized project `project2` at `/home/jmacey/Project2`
[jmacey@w12000]~% cd Project2
[jmacey@w12000]~/Project2% uv run main.py
Using CPython 3.13.5
Creating virtual environment at: .venv
Hello from project2!

adding dependencies

All of the project settings are managed by two files. The pyproject.toml and the uv.lock file. These should be added to any version control you use as they are responsible for locking and syncing of the projects. To do this we use. If you are used to using pip you can still use it (and requirements.txt) however it is best to use uv now.

adding dependencies

uv sync
Resolved 1 package in 0.47ms
Audited in 0.00ms

At present the pyproject.toml is as follows.

[project]
name = "project2"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = []

adding dependencies

As you can see there are no dependencies as yet, it is simple to add one for example numpy.

uv add numpy
Resolved 2 packages in 140ms
Prepared 1 package in 223ms
Installed 1 package in 19ms
+ numpy==2.3.1

Inspecting pyproject.toml will now reveal.

[project]
name = "project2"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
    "numpy>=2.3.1",
]

testing

To check this we can use the uv run python command to run the REPL and test.

uv run python
Python 3.13.5 (main, Jun 26 2025, 21:20:04) [Clang 20.1.4 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__version__
'2.3.1'

Adding more packages

Any number of packages can be installed like this, or by manually editing the pyproject.toml file. By default, uv uses the Python Package Index (PyPI) for dependency resolution and package installation. However, uv can be configured to use other package indexes, including private indexes, via the [[tool.uv.index]] configuration option (and –index, the analogous command-line option). Versions can also be specified, for example to install a specific version of numpy we can use :-

uv add numpy==2.3.1

Self Study

https://code.visualstudio.com/docs/python/python-tutorial

Next