Python Packaging system (uv)

Python uses a system called 'virtual environment' to define where to install packages, which python version to use, and what libraries you can import in your scripts. Since different libraries may depend on specific versions of other libraries, the packaging system has to construct a graph of dependencies and ensure all conditions can be met. This is done by the famous pip in the python world.

However, pip is very slow, and so we use modern tools like uv which claim to be 10 to 100x faster, with a friendlier interface.

To begin, install uv (pay attention to any messages it may return):

Linux, Mac, Windows with WSL:

curl -LsSf https://astral.sh/uv/install.sh | sh

To start a 'project' (i.e. create a virtual environment) in the current directory (thesis-template):

uv init

This creates the following files:

  • .python-version: The version of python we are using

  • pyproject.toml: The details of our python library/application. Modify as needed.

[project]
name = "thesis"
version = "0.1.0"
description = "Python repository for thesis"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []
  • hello.py: An example program

Now, we can install the packages we want, for instance:

uv add numpy pandas matplotlib scikit-learn rich
# Using CPython 3.12.3 interpreter at: /usr/bin/python3.12
# Creating virtual environment at: .venv
# Resolved 23 packages in 16.76s

This installs the packages and also creates:

  • uv.lock: File with which uv keeps track of packages and their versions.

  • .venv/: The folder where all packages will be installed.


Activate the virtual environment that was created:

Select interpreter in VS Code


To confirm that everything works as intended, add the following at the start of hello.py:

import pandas
import matplotlib
import numpy
import sklearn
import rich

Now run the script in the console:

python hello.py

It should run without errors.