Installation#

SLEAP can be installed as a Python package on Windows, Linux, and Mac OS.

SLEAP requires many complex dependencies, so we strongly recommend using a package manager such as Miniconda to install SLEAP in its own isolated environment. See the Miniconda website for installation instructions. The Anaconda or Mamba package managers will also work well; however, take care not to install multiple different conda-based package managers - choose one and stick with it.

The newest version of SLEAP can always be found in the Releases page.

Hint

Installation requires entering commands in a terminal. To open one:

Windows: Open the Start menu and search for the Miniforge Prompt (if using Mambaforge) or the Command Prompt if not.

Note

On Windows, our personal preference is to use alternative terminal apps like Cmder or Windows Terminal.

Linux: Launch a new terminal by pressing Ctrl + Alt + T.

Mac: Launch a new terminal by pressing Cmd + Space and searching for Terminal.

Note

If you already have Anaconda on your computer (and it is an older installation), then make sure to set the solver to libmamba in the base environment.

conda update -n base conda
conda install -n base conda-libmamba-solver
conda config --set solver libmamba

Warning

Any subsequent mamba commands in the docs will need to be replaced with conda if you choose to use your existing Anaconda installation.

Installation methods#

SLEAP can be installed three different ways: via conda package, conda from source, or pip package. Select one of the methods below to install SLEAP. We recommend conda package.

conda package#

mamba create -y -n sleap -c conda-forge -c nvidia -c sleap -c anaconda sleap=1.4.1a1

Note

  • This comes with CUDA to enable GPU support. All you need is to have an NVIDIA GPU and updated drivers.

  • If you already have CUDA installed on your system, this will not conflict with it.

  • This will also work in CPU mode if you don’t have a GPU on your machine.

This is the recommended installation method.

conda from source#

  1. First, ensure git is installed:

    git --version
    

    If ‘git’ is not recognized, then install git.

  2. Then, clone the repository:

    git clone https://github.com/talmolab/sleap && cd sleap
    
  3. Finally, install SLEAP from the environment file:

    mamba env create -f environment.yml -n sleap
    

    This is the recommended method for development.

Note

  • This installs SLEAP in development mode, which means that edits to the source code will be applied the next time you run SLEAP.

  • Change the -n sleap in the command to create an environment with a different name (e.g., -n sleap_develop).

pip package#

Although you do not need Mambaforge installed to perform a pip install, we recommend installing Miniconda to create a new environment where we can isolate the pip install. Alternatively, you can use a venv if you have an existing python installation. If you are working on Google Colab, skip to step 3 to perform the pip install without using a conda environment.

  1. Otherwise, create a new conda environment where we will pip install sleap:

    mamba create --name sleap pip python=3.7.12 cudatoolkit=11.3 cudnn=8.2
    
  2. Then activate the environment to isolate the pip install from other environments on your computer:

    mamba activate sleap
    

    Warning

    Refrain from installing anything into the base environment. Always create a new environment to install new packages.

  3. Finally, we can perform the pip install:

    pip install sleap[pypi]==1.4.1a1
    

    This works on any OS except Apple silicon and on Google Colab.

    Note

    The pypi distributed package of SLEAP ships with the following extras:

    • pypi: For installation without an mamba environment file. All dependencies come from PyPI.

    • jupyter: This installs all pypi and jupyter lab dependencies.

    • dev: This installs all jupyter dependencies and developement tools for testing and building docs.

    • conda_jupyter: For installation using a mamba environment file included in the source code. Most dependencies are listed as conda packages in the environment file and only a few come from PyPI to allow jupyter lab support.

    • conda_dev: For installation using a mamba environment with a few PyPI dependencies for development tools.

    Note

    • Requires Python 3.7

    • To enable GPU support, make sure that you have CUDA Toolkit v11.3 and cuDNN v8.2 installed.

    Warning

    This will uninstall existing libraries and potentially install conflicting ones.

    We strongly recommend that you only use this method if you know what you’re doing!

Testing that things are working#

If you installed using mamba, first activate the sleap environment by opening a terminal and typing:

mamba activate sleap

Hint

Not sure what mamba environments you already installed? You can get a list of the environments on your system with:

mamba env list

GUI support#

To check that the GUI is working, simply type:

sleap-label

You should see the SLEAP labeling interface pop up within a few moments.

Importing#

To check if SLEAP is installed correctly in non-interactive environments, such as remote servers, confirm that you can import it with:

python -c "import sleap; sleap.versions()"

Output:

(sleap_develop) λ python -c "import sleap; sleap.versions()"
SLEAP: 1.2.0
TensorFlow: 2.7.1
Numpy: 1.21.5
Python: 3.7.11
OS: Windows-10-10.0.19041-SP0

GPU support#

Assuming you installed using either of the mamba-based methods on Windows or Linux, SLEAP should automatically have GPU support enabled.

To check, verify that SLEAP can detect the GPUs on your system:

python -c "import sleap; sleap.system_summary()"

Output:

(sleap_develop) λ python -c "import sleap; sleap.system_summary()"
GPUs: 2/2 available
  Device: /physical_device:GPU:0
         Available: True
        Initalized: False
     Memory growth: None
  Device: /physical_device:GPU:1
         Available: True
        Initalized: False
     Memory growth: None

SLEAP uses TensorFlow for GPU acceleration. To directly check if TensorFlow is detecting your GPUs:

python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

Output:

(sleap_develop) λ python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU'), PhysicalDevice(name='/physical_device:GPU:1', device_type='GPU')]

Note

  • GPU support requires an NVIDIA GPU.

  • If you haven’t yet (or in a while), update to the latest NVIDIA drivers for your GPU.

  • We use the official conda packages for cudatoolkit and cudnn, so no external installations are required. If you already have those installed on your system, they should not interfere with the ones in the SLEAP environment.

  • TensorFlow 2.6-2.8 are compatible with CUDA Toolkit v11.3 and cuDNN v8.2.

Warning

TensorFlow 2.7+ is currently failing to detect CUDA Toolkit and CuDNN on some systems (see Issue thread).

If you run into issues, either try downgrading the TensorFlow 2.6:

pip install tensorflow==2.6.3

or follow the note below.

Note

If you are on Linux, have a NVIDIA GPU, but cannot detect your GPU:

W tensorflow/stream_executor/platform/default/dso_loader.cc:64 Could not load dynamic
library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object
file: No such file or directory

then activate the environment:

mamba activate sleap

and run the commands:

mkdir -p $CONDA_PREFIX/etc/conda/activate.d
echo '#!/bin/sh' >> $CONDA_PREFIX/etc/conda/activate.d/sleap_activate.sh
echo 'export SLEAP_OLD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH' >> $CONDA_PREFIX/etc/conda/activate.d/sleap_activate.sh
echo 'export LD_LIBRARY_PATH=$CONDA_PREFIX/lib:$LD_LIBRARY_PATH' >> $CONDA_PREFIX/etc/conda/activate.d/sleap_activate.sh
source $CONDA_PREFIX/etc/conda/activate.d/sleap_activate.sh

This will set the environment variable LD_LIBRARY_PATH each time the environment is activated. The environment variable will remain set in the current terminal even if we deactivate the environment. Although not strictly necessary, if you would also like the environment variable to be reset to the original value when deactivating the environment, we can run the following commands:

mkdir -p $CONDA_PREFIX/etc/conda/deactivate.d
echo '#!/bin/sh' >> $CONDA_PREFIX/etc/conda/deactivate.d/sleap_deactivate.sh
echo 'export LD_LIBRARY_PATH=$SLEAP_OLD_LD_LIBRARY_PATH' >> $CONDA_PREFIX/etc/conda/deactivate.d/sleap_deactivate.sh

These commands only need to be run once and will subsequently run automatically upon [de]activating your sleap environment.

Upgrading and uninstalling#

We strongly recommend installing SLEAP in a fresh environment when updating. This is because dependency versions might change, and depending on the state of your previous environment, directly updating might break compatibility with some of them.

To uninstall an existing environment named sleap:

mamba env remove -n sleap

Hint

Not sure what mamba environments you already installed? You can get a list of the environments on your system with:

mamba env list

Once the environment has been removed, you are free to install SLEAP using any of the installation methods above into an environment of the same name.

Getting help#

If you run into any problems, check out the Github Discussions and GitHub Issues to see if others have had the same problem.

If you get any errors or the GUI fails to launch, try running the diagnostics to see what SLEAP is able to detect on your system:

sleap-diagnostic

If you were not able to get SLEAP installed, activate the mamba environment it is in and generate a list of the package versions installed:

mamba list

Then, open a new Issue providing the versions from either command above, as well as any errors you saw in the console during the installation. Or start a discussion to get help from the community.