napari is a Python application and package, so it requires a working Python installation. There are multiple ways that Python installations and packages can be managed. For a detailed breakdown, we recommend this excellent guide and tutorial by Talley Lambert (Harvard Medical School).
Installing Python using conda¶
In this tutorial, we will install Python via miniforge, a distribution of Python based in the conda package manager.
In your web browser, go to:
https://conda -forge .org /download/ Click on the tile corresponding to your platform (e.g., Windows, macOS, or Linux) to download the installer. If you are unsure about your macOS or Linux architecture, open a command line terminal and run:
uname -mAlternately, you can also download the installer using the command line on macOS or Linux by running:
curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"Once you have downloaded miniforge installer, run it to install conda. Note: you may need admin permissions during the installation process.
Windows¶
- Find the file you downloaded (e.g. in your Downloads directory), it should look like
Miniforge3-Windows-x86_64.exe. - Double-click with the left mouse button to execute it.
- Follow the instructions to complete the installation. We recommend checking the options to “Create start menu shortcuts” and “Add Miniforge3 to my PATH environment variable”.
- Once the installation has completed, you can verify it was correctly installed by searching for the “miniforge prompt” in your Start menu.
macOS & Linux¶
- Find the file you downloaded (e.g. in your Downloads directory), it should look like
Miniforge3-MacOSX-arm64.shorMiniforge3-Linux-x86_64.sh. - Using the command line, navigate to the location of the installer. For example, if it’s in the Downloads directory, you can run:
cd ~/Downloads- Run the installer by typing:
bash Miniforge3-$(uname)-$(uname -m).shThe installer will walk you through a series of prompts to complete the installation. We recommend that you use the default installation location, but you can change it to a different location in your user directory if you prefer.
Once the installation finishes, the installer will ask:
Do you wish to update your shell profile to automatically initialize conda?
We recommend you answeryesto this question. This will add the necessary lines to your shell profile to ensure thatcondais added to your PATH variable and properly initialized when you open a new shell. Note: For changes to take effect, you will need to close and re-open your current shell.Once the installation has completed, you can verify it was correctly installed by opening a new command line. You should see
(base)next to your command line prompt. Additionally, the following command:echo $CONDA_PREFIXshould return the path to your
miniforgeinstallation, by default this is~/miniforge3(i.e.,miniforge3in your home directory), so for example:/Users/username/miniforge3or
/home/username/miniforge3
Manual initialization¶
If you did not have the installer initialize your shell, you can manually initialize it. Note: the command depends on installation location of
miniforge, by default this is~/miniforge3. Then, run:~/miniforge3/condabin/conda initAgain, for changes to take effect, you will need to close and re-open your current shell.
- Find the file you downloaded (e.g. in your Downloads directory), it should look like
Setting up your napari workshop environment¶
Open your terminal.
- Windows: Open the “miniforge prompt” from your start menu
- Mac OS: Open Terminal (you can search for it in spotlight -
cmd+space) - Linux: Open your terminal application
We will use a virtual environment to encapsulate the Python tools used for this workshop. This ensures that the requirements for this workshop do not interfere with any other Python projects. To create the environment (named
napari-workshop) with Python 3.11 in it, enter the following command:conda create -n napari-workshop -c conda-forge python=3.12 napari pyqt jupyterlabOnce the environment setup has finished, activate the environment:
conda activate napari-workshopIf you successfully activated the environment, you should now see
(napari-workshop)to the left of your command prompt.Test that your notebook installation is working. We will be using notebooks for interactive analysis. Enter the command below and it should launch the
jupyter labapplication in a web browser. Once you’ve confirmed it launches, close the web browser and pressctrl+cin the terminal window to stop the notebook server.jupyter labTest your napari installation. Enter the command below and an empty napari viewer should open. You can close the window after it opens using the File menu. Please note that it takes a bit of extra time (as much as 60 s) to launch napari the first time, particularly if your computer has security and virus scan applications running.
napari
This installation guide has been reproduced and edited from an introductory napari tutorial at the Jackson Laboratory.