UV is an extremely fast Python package and project manager, written in Rust and created by Astral (high performance next-gen python tooling). It is a tool designed to replace pip, pip-tools, and virtualenv.
Installation:
Load the appropriate Python Module (check with module spider Python)
module load Python # uv can even install different Python versions
Install Binaries in the specified location. It can be installed using pip or conda but can encounter libgcc dependency issue.
curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR="<installation-path>" sh
Set the UV environment. Path can be set to ~/.bashrc or ~/.bash_profile but it is not recommended
export PATH="<installation-path>:$PATH" # ‘source <installtion-path>/env’ will update .bashrc file
Check the Installed packages
uv pip list
Project Management:
Initialize a project - manages project dependencies and environments, with support for lockfiles, workspaces, and more
uv init --directory <installation-path>
Change directory to the project path
cd <installation-path> # provides path to virtual environment
Install a package “ruff” (Python linter - analysis tool for bugs, syntax errors etc. and code formatter) in a virtual environment in uv project and then install “numpy” package
uv add ruff # add the package to pyproject.toml; for std application development
uv pip install numpy # direct package installation; uses the current activated environment
Running Python Script:
Make sure to load the same Python module and change directory to project path (e..g <installtion-path> before running the python script. Also check Interactive/Batch job submission.
python <python-script>.py
Example: Creating a LLM agent:
Copy the "uv" directory from /usr/local/doc/UV to your working directory and find the job file (job.slurm) and python script "deepagent.py" and change directory to uv
cp -r /usr/local/doc/UV/uv </path>
cd <path>/uv
Update the slurm file with your Hugging Face Token (API Keys)
Register/Sign on -> Profile -> Settings -> Access Tokens -> Create New Token
Submit the job and check slurm-<jobid>.out file
sbatch job.slurm