Installation¶
Prerequisites:
Python 3.11 (or) 3.12 (or) 3.13 (required for all installation methods)
Python 3.14 is not yet supported
sleap-nn currently supports Python 3.11, 3.12, and 3.13. Python 3.14 is not yet tested or supported. If you have Python 3.14 installed, you must specify the Python version in all uv install commands by adding --python 3.13.
For example:
# for uv tool install
uv tool install --python 3.13 "sleap-nn[torch]" ...
# for uvx
uvx --python 3.13 ...
# for uv add setup; specify version in uv init
uv init --python 3.13
# for uv sync
uv sync --python 3.13 ...
... with the rest of your install command as needed.
Choose Your Installation Method
- Installation as a system-wide tool with uv: (Recommended) Use
uv tool installto install sleap-nn globally as a CLI tool - Installation with uvx: Use
uvxfor one-off commands (no installation needed) - Installation with uv add: Use
uv addto install sleap-nn as a dependency in a uv virtual env. (useful for project-specific workspaces) - Installation with pip: Use
pipto install from pypi in a conda env. (Recommended to use with a conda env) - Installation from source: Use
uv syncto install from source (for developmental purposes) - Installing Pre-release Versions: For testing alpha/beta releases
Installation as a system-wide tool with uv¶
uv tool install installs sleap-nn globally as a system-wide CLI tool, making sleap-nn commands available from anywhere in your terminal.
Install uv
Install uv - a fast Python package manager:
Platform-Specific Installation¶
uv Version Requirement
The --torch-backend option requires uv 0.9.20 or later. Check your version:
Info
- The
--torch-backend autooption automatically detects your GPU and installs the optimal PyTorch version. - For manual selection, use
--torch-backend cu130(CUDA 13),--torch-backend cu128(CUDA 12.8),--torch-backend cu118(CUDA 11.8), or--torch-backend cpu. - On macOS, MPS (Metal Performance Shaders) is automatically enabled for Apple Silicon acceleration.
Verify installation¶
Updating Dependencies¶
To update sleap-nn and its dependencies (e.g., sleap-io) to their latest versions:
Note
When upgrading, uv respects any version constraints specified during installation. The upgrade will only update within those constraints. To change version constraints, reinstall with new specifications using uv tool install.
Installation with uvx¶
uvx automatically installs sleap-nn and runs your command inside a temporary virtual environment (venv). This means each run is fully isolated and leaves no trace on your system—perfect for trying out sleap-nn without any permanent installation.
Install uv
Install uv - a fast Python package manager:
Platform-Specific Commands¶
Note
- The
--torch-backend autooption automatically detects your GPU and installs the optimal PyTorch version. Requires uv 0.9.20+. - For manual selection, use
--torch-backend cu130(CUDA 13),--torch-backend cu128(CUDA 12.8), or--torch-backend cpu. - On macOS, MPS (Metal Performance Shaders) is automatically enabled for Apple Silicon acceleration.
uvx Installation
Because uvx installs packages fresh on every run, it's ideal for quick tests or use in remote environments. For regular use, you could install with uv tool install or setting up a development environment with uv sync to avoid repeated downloads.
Updating Dependencies¶
With uvx, no separate update command is needed:
Automatic Updates
uvx automatically fetches and installs the latest version of sleap-nn and its dependencies (e.g., sleap-io) each time you run a command. This means you're always using the most recent version unless you specify version constraints like uvx "sleap-nn[torch]==0.0.3" ....
To ensure you're using the latest version, simply run your uvx command as usual - it will automatically download and use the newest available version.
Installation with uv add¶
This method creates a dedicated project environment using uv's modern Python project management. It initializes a new project with uv init, creates an isolated virtual environment with uv venv, and adds sleap-nn as a dependency using uv add. To use all installed packages, you must run commands with uv run (e.g., uv run sleap-nn train ... or uv run pytest ...).
Install and set-up uv
Step-1: Install uv - a fast Python package manager:
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
Step-2: Move to your project directory and initialize the virtual env.
Platform-Specific Installation¶
How uv add works
- When you run
uv init, it creates apyproject.tomlfile in your working directory to manage your project's dependencies. - When you use
uv add sleap-nn[torch], it addssleap-nn[torch]as a dependency in yourpyproject.tomland installs it in your virtual environment. - To add other packages, simply run
uv add <package>. After adding new packages, you should runuv syncto update your environment with all dependencies specified inpyproject.toml. (oruv sync --upgradeto update all dependencies) - To install a local package (such as a local clone of sleap-nn) in editable mode, use: This is useful for development, as changes to the code are immediately reflected in your environment.
Windows: MarkupSafe Installation Issue
On Windows, you may encounter errors when running uv add "sleap-nn[torch]" --index ... due to an incompatibility with the MarkupSafe wheel (e.g., "failed to install MarkupSafe" or similar errors).
Similar issues: #11532 and #12620.
Workaround:
Before running uv add "sleap-nn[torch]" ... on Windows, manually install a compatible version of MarkupSafe:
uv add git+https://github.com/pallets/[email protected]
Then proceed with:
Info
- For more information on which CUDA version to use for your system, see the PyTorch installation guide.
The--indexin the install command should match the CUDA version you need (e.g.,https://download.pytorch.org/whl/cu118for CUDA 11.8,https://download.pytorch.org/whl/cu128for CUDA 12.8, etc.). - On macOS, MPS (Metal Performance Shaders) is automatically enabled for Apple Silicon acceleration.
Verify Installation¶
sleap-nn not recognized after installation?
If running the verification step above gives an error like sleap-nn: command not found or 'sleap-nn' is not recognized as an internal or external command, try the following workarounds:
-
Activate your virtual environment (the venv name should be the same as your current working dir name). If you used
This ensures the command runs in the correct environment.uv, activate it and then run: -
Another workaround (not recommended): Check if you have any empty
pyproject.tomloruv.lockfiles inUsers/<your-user-name>. If you find empty files with these names, delete them and try again. (Empty files here can sometimes interfere with uv's environment resolution.)
Updating Dependencies¶
To update sleap-nn and its dependencies to their latest versions:
Note
uv add --upgrade-package <package>forces the specified package to update to its latest compatible version, even if a valid version is already installed.uv sync --upgraderefreshes the entire lockfile and updates all dependencies to their newest compatible versions while maintaining compatibility with yourpyproject.tomlconstraints.- By default,
uv addonly updates the locked version if necessary to satisfy new constraints. Use--upgrade-packageto force an update.
Installation with pip¶
We recommend creating a dedicated environment with conda or mamba/miniforge before installing sleap-nn with pip. This helps avoid dependency conflicts and keeps your Python setup clean. After installing Miniconda or Miniforge, create and activate an environment, then run the pip install commands below inside the activated environment.
Python 3.14 is not yet supported
SLEAP currently supports Python 3.11, 3.12, and 3.13. Python 3.14 is not yet tested or supported.
To create a conda environment, run:
Platform-Specific Installation¶
Info
- For more information on which CUDA version to use for your system, see the PyTorch installation guide.
The--extra-index-urlin the install command should match the CUDA version you need (e.g.,https://download.pytorch.org/whl/cu118for CUDA 11.8,https://download.pytorch.org/whl/cu128for CUDA 12.8, etc.). - On macOS, MPS (Metal Performance Shaders) is automatically enabled for Apple Silicon acceleration.
Verify Installation¶
# Test the installation
sleap-nn --help
# Check PyTorch installation
python -c "import torch; print(f'PyTorch: {torch.__version__}'); print(f'CUDA available: {torch.cuda.is_available()}')"
Updating Dependencies¶
To update sleap-nn and its dependencies to their latest versions:
Upgrading Specific Dependencies
To upgrade a specific dependency like sleap-io independently:
Installation from source¶
For contributing to sleap-nn or development workflows.
uv sync
uv sync creates a .venv (virtual environment) inside your current working directory. This environment is only active within that directory and can't be directly accessed from outside. To use all installed packages, you must run commands with uv run (e.g., uv run sleap-nn train ... or uv run pytest ...).
1. Clone the Repository¶
2. Install uv¶
3. Install Dependencies¶
4. Updating Dependencies¶
To update sleap-nn and its dependencies to their latest versions:
How --upgrade Works
The --upgrade flag refreshes the lockfile and updates all dependencies to their newest compatible versions while maintaining compatibility with your pyproject.toml constraints. This ensures you have the latest versions of all dependency packages.
Verify Installation¶
In your working dir (where you ran uv sync):
# Run tests
uv run pytest tests
# Check code formatting
uv run black --check sleap_nn tests
uv run ruff check sleap_nn/
# Run CLI commands
uv run sleap-nn train ...
uv run sleap-nn track ...
Installing Pre-release Versions¶
Pre-release versions (alpha, beta, release candidates) require explicit opt-in since they are excluded by default per PEP 440.
Why Pre-releases?¶
Pre-release versions like 0.1.0a0 let us test new features and breaking changes with a smaller group before a stable release. Users won't accidentally get pre-releases unless they explicitly opt in.
Installation Commands¶
Pin to Specific Version¶
To install a specific pre-release version:
# uv tool install
uv tool install "sleap-nn[torch]==0.1.0a0" --torch-backend auto
# pip
pip install "sleap-nn[torch]==0.1.0a0" --index-url https://pypi.org/simple --extra-index-url https://download.pytorch.org/whl/cu128
Environment Variable¶
For repeated use, you can set the environment variable:
This makes all uv commands default to allowing pre-releases.
Troubleshooting¶
Import Errors¶
If you get import errors:
- Verify PyTorch is installed:
python -c "import torch; print(torch.__version__)" - Try reinstalling with torch extras
CUDA Issues¶
If you encounter CUDA-related errors:
- Verify your NVIDIA drivers are up to date
- Check CUDA compatibility with PyTorch version
- Try the CPU-only installation as a fallback