uv is a fast Python package and virtual environment manager developed by Astral. It provides functionality provided by both venv and pip, but is significantly faster at dependency resolution. Some users who do not need Conda packages or cross-language support in their project may prefer to use uv for its speed. Because uv is still under active development and its behavior may change between frequent releases, OSC does not currently provide it as a centrally managed software package. However, users who wish to use uv may install it in their home directory and manage their own installation.
Install uv
To install uv on OSC systems, please manually download the install.sh script for the latest release:
wget https://astral.sh/uv/install.sh
Then, run the following commands to install uv in its own folder in your home directory:
chmod +x install.sh mkdir -p $HOME/osc_apps/uv UV_INSTALL_DIR="$HOME/osc_apps/uv" INSTALLER_NO_MODIFY_PATH=1 ./install.sh
The default uv installation procedure modifies a user's .bashrc and installs binaries into location that may not be appropriate for OSC systems. Installing uv into a dedicated location in your home directory as described above avoids creating conflicts with other modules.
Create a Local Module
After installation, OSC recommends you create a local module so that uv can be loaded into your PATH with module load uv/<version> when you want to use it. Modules allow you to dynamically alter your environment to define environment variables and bring executables, libraries, and other features into your shell's search paths. These instructions are for uv version 0.11.29.
We will be using the filename 0.11.29.lua ("version".lua). A simple Lua module for our uv installation would be:
-- Local Variables local name = "uv" local version = "0.11.29" -- Locate Home Directory local homedir = os.getenv("HOME") # This is for the path $HOME/osc_apps/uv local root = pathJoin(homedir, "osc_apps", name)-- Set Basic Paths prepend_path("PATH", pathJoin(root, "bin"))prepend_path("LD_LIBRARY_PATH", root .. "/lib") prepend_path("LIBRARY_PATH", root .. "/lib") prepend_path("INCLUDE", root .. "/include") prepend_path("CPATH", root .. "/include") prepend_path("PKG_CONFIG_PATH", root .. "/lib/pkgconfig")prepend_path("MANPATH", root .. "/share/man")
Copy this to a file and save it to your local module directory at $HOME/osc_apps/lmodfiles/uv.
Initializing Modules
To make this module usable, you need to tell lmod where to look for it. You can do this by issuing the command module use $HOME/osc_apps/lmodfiles in our example. You can see this change by performing module avail. This will allow you to load your software using module load uv/0.11.29.
More information about locally installing software and creating local modules can be found at HOWTO: Locally Installing Software.
Create a virtual environment
Before creating a virtual environment with uv, load your local uv module and an OSC Python module. If you do not load a Python module, uv will install and manage its own version of Python, which may be less optimized for OSC's systems.
To load these modules:
module load python/<version> uv/<version>
You can use module spider python to see which versions of python are available on a given system.
Then, to create a uv virtual environment, run:
uv venv --no-managed-python local
This creates an environment in the current directory called local. Using --no-managed-python means that uv will use the current Python module that you have loaded.
Activate and deactivate the virtual environment
First, load the Python module you used when you created the enviroment:
module load python/<version>
To activate your uv virtual environment (named local here), run:
source local/bin/activate
To deactivate your uv virtual environment, run:
deactivate
Install packages
uv can install packages from PyPi. To install a package with uv, run:
uv pip install package
Where package is the name of the package you want to install.
Further Reading