# uv and pixi on computer centers
[TOC]
## `uv` - https://docs.astral.sh/uv/
> An extremely fast Python package and project manager, written in Rust.
> A single tool to replace pip, pip-tools, pipx, poetry, pyenv, twine, virtualenv, and more.
### Install and configure uv
```bash
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Redirect cache and tools in project folder
export UV_CACHE_DIR=/crex/proj/uppmax-xxx/user/nobackup/.UV_CACHE_DIR
export UV_TOOL_DIR=/crex/proj/uppmax-xxx/user/nobackup/.UV_TOOL_DIR
# make the folders
mkdir -p $UV_CACHE_DIR $UV_TOOL_DIR
```
### Run python tools without installation
```bash
# run python tool without installing it
uvx nf-core
```
### Install python tools
Python modules (tools) that are executable will be installed in own environment and made available in your `$PATH` to run them directly. Example installation with `nf-core`
```bash
# install nf-core
uv tool install nf-core
# list tools
uv tool list
# update tool
uv tool update nf-core
# update all tools
uv tool update --all
# uninstall tool
uv tool uninstall nf-core
```
### Maintaining uv
```bash
# update uv
uv self update
# clean cache
uv cache clean
```
For more details - follow the [documentation](https://docs.astral.sh/uv/) online.
## Offline installation with uv
### Examples
::: spoiler forest - https://github.com/onnela-lab/forest
```bash
# Load uv on Rackham (or computer with uv installed and Internet)
source /sw/generic/uv-tools/setup/source.me
# Clone the repository
git clone https://github.com/onnela-lab/forest.git
cd forest
mkdir cache
# On Rackhama and Bianca you might need newer gcc and cmake
module load gcc cmake
# Create the .venv that will also download the required packages
uv sync --cache-dir cache
# Remove the .venv - it will be recreated on Bianca
rm -r .venv
# On Bianca
# Load uv on Bianca
source /sw/generic/uv-tools/setup/source.me
# copy or move the forest folder in your project
# collecting the folder in a .tar file is a good idea
cd forest
uv sync --cache-dir cache --offline
source .venv/bin/activate
(beiwe-forest) [user@sensXXXXXXX-bianca forest]$ python3
Python 3.13.3 (main, May 17 2025, 13:49:13) [Clang 20.1.4 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> from forest.bonsai.simulate_log_data import sim_log_data
>>> from forest.bonsai.simulate_gps_data import sim_gps_data, gps_to_csv
... from forest.jasmine.traj2stats import Frequency, gps_stats_main
... from forest.willow.log_stats import log_stats_main
...
>>>
deactivate
```
:::
---
## `pixi` - https://pixi.sh/latest/
> Pixi is a package management tool for developers. It allows the developer to install libraries and applications in a reproducible way. Use pixi cross-platform, on Windows, Mac and Linux.
### Install and configure pixi
```bash
# Install pixi
curl -fsSL https://pixi.sh/install.sh | bash
# Redirect cache and globals in project folder
export PIXI_CACHE_DIR=/crex/proj/uppmax-xxx/user/nobackup/.PIXI_CACHE_DIR
export PIXI_HOME=/crex/proj/uppmax-xxx/user/nobackup/.PIXI_HOME
# make the folders
mkdir -p $PIXI_CACHE_DIR $PIXI_HOME
# add global bin to $PATH
export PATH=$PATH:$PIXI_HOME/bin
```
### Install tools globally
```bash
pixi global install -c bioconda -c conda-forge samtools
Global environments as specified in '/sw/apps/pixi/manifests/pixi-global.toml'
└── samtools: 1.9 (installed)
└─ exposes: ace2sam, blast2sam, bowtie2sam, export2sam, interpolate_sam, maq2sam-long, maq2sam-short, md5fa, md5sum-lite, novo2sam, plot-bamstats, psl2sam, sam2vcf, samtools, seq_cache_populate, soap2sam, wgsim, wgsim_eval, zoom2sam
# list global tools
pixi global list
Global environments as specified in '/crex/proj/uppmax-xxx/user/nobackup/.PIXI_HOME/manifests/pixi-global.toml'
└── samtools: 1.9
└─ exposes: ace2sam, blast2sam, bowtie2sam, export2sam, interpolate_sam, maq2sam-long, maq2sam-short, md5fa, md5sum-lite, novo2sam, plot-bamstats, psl2sam, sam2vcf, samtools, seq_cache_populate, soap2sam, wgsim, wgsim_eval, zoom2sam
# Update global tool
pixi global update samtools
# Update all tools
pixi global update
```
### Maintain pixi
```bash
# Update pixi
pixi self-update
# clean cache
pixi clean cache
```
## pixi-pack
https://pixi.sh/latest/deployment/pixi_pack/
There is a convenient way to pack whole environment/project (*download all necessary packages and wrap them in a single file*) and unpack it on another machine into a new environment (*even without conda or pixi available on that machine*).
```bash!
# Install pixi-pack as global tool
pixi global install pixi-pack pixi-unpack
# Init new project
pixi init --platform linux-64 -c conda-forge -c bioturing -c bioconda CellTrek
# Add packages
cd CellTrek
pixi add bioturing::r-celltrek "r-seurat<5.0" "r-seuratobject<5.0" bioconda::bioconductor-consensusclusterplus
pixi-pack --use-cache ./cache
# Then unpack on the other computer with
pixi-unpack environment.tar
# or create executable that can unpack itself
pixi-pack --create-executable --use-cache ./cache
# on the other machine create folder and run to unpack
./environment.sh
# Use conda to activate the environment
conda activate /full/path_to_env
```
### Examples
::: spoiler gsMap
```bash
pixi init --platform linux-64 -c conda-forge -c bioconda gsMap
cd gsMap
pixi add "python>=3.10" bioconda::gsmap
# Test the setup
pixi shell
(gsMap) gsmap -v
gsMap version 1.73.5
exit
# then pixi-pack ... and so on...
```
:::
## Contacts:
- [Pavlin Mitev](https://katalog.uu.se/profile/?id=N3-1425)
- [UPPMAX](https://www.uu.se/en/centre/uppmax)
- [AE@UPPMAX - related documentation](/8sqXISVRRquPDSw9o1DizQ)