Skip to content

uv

An extremely fast Python package and project manager written in Rust.


uv requires an environment module

In order to use uv, you must first load the appropriate environment module:

module load python-uv

uv is a package and project manager for Python, written in Rust. It is designed to be extremely fast and efficient, with a focus on performance and ease of use. It is a drop-in replacement for pip and venv, and can be used to manage Python packages and projects in a similar way.

Using uv on the HPC#

To get started with uv on the HPC, follow the setup instructions below to load the necessary modules and prepare your environment.

First, before using uv, clear any existing environments:

$ conda deactivate        # Deactivate any active Conda environments
Then, load the required modules:
$ module load webproxy    # Enables internet access for downloading packages on compute nodes (e.g. when running in OOD)
$ module load python-uv   # Loads the uv-based Python environment

Or as a single command to set up your environment:

$  ml purge && conda deactivate && ml webproxy python-uv

Creating a Project with uv#

You can create a new Python project using the uv init command:

$ uv init hello-world 
$ cd hello-world

Alternatively, you can initialize a project in the working directory:

1
2
3
$ mkdir hello-world
$ cd hello-world
$ uv init

uv will create the following files:

1
2
3
4
5
├── .gitignore
├── .python-version
├── README.md
├── main.py
└── pyproject.toml

The `main.py file contains a simple "Hello world" program. Try it out with uv run:

$ uv run main.py
Hello from hello-world!

Creating and Activating a Virtual Environment#

You can use uv to create a virtual environment just like with venv:

$ uv venv ~/myenv               # Create virtual environment in ~/myenv
$ source ~/myenv/bin/activate   # Activate the environment

To deactivate your environment:

(myenv) $ deactivate

Using Python with uv#

Once your environment is activated, you can install packages using uv’s pip interface:

(myenv) $ uv pip install flask   # Installs Flask

Specifying Python Versions with uv#

You can create virtual environments with specific Python versions using the --python flag.

If a specific Python version is not specified, uv will use the default Python version available in the environment:

1
2
3
4
5
6
$ uv venv ~/myenv
$ source ~/myenv/bin/activate
(myenv) $ which python
~/myenv/bin/python
(myenv) $ python --version
Python 3.13.3

To specify a Python version, you can use the --python option. For example, to create a virtual environment with Python 3.13:

1
2
3
4
$ uv venv ~/myenv --python 3.12
$ source ~/myenv/bin/activate
(myenv) $ python --version
Python 3.12.10

Note

While uv can be used with beta versions of Python, this is not recommended, as many community-contributed modules may not function correctly until an official Python release is available.

Using uv with OOD Jupyter Notebooks#

To use uv within Jupyter Notebooks on Open OnDemand (OOD) you must select the proper Python version and type of environment when launching your notebook.

When filling out the job submission form for your Jupyter Notebook, select the following options: - Python version (required): "python-uv/latest" Python Version Screenshot - Type of Environment Jupyter is installed in: "UV Virtual Environment" or "UV Project" Type of Environment Screenshot or Type of Project Screenshot