Setting up a development installation#

In order to make changes to napari, you will need to fork the repository. If you are not familiar with git, we recommend reading up on this guide.

  1. Clone the forked repository to your local machine and change directories:

    git clone https://github.com/your-username/napari.git
    cd napari
    
  2. Set the upstream remote to the base napari repository:

    git remote add upstream https://github.com/napari/napari.git
    
  3. If you haven’t already, create a development environment:

    After installing conda, create an environment called napari-env with Python 3.10 and activate it.

    conda create -y -n napari-env -c conda-forge python=3.10
    conda activate napari-env
    

    After installing Python on your machine, create a virtual environment on your terminal and activate it. On Linux and macOS, you can run

    python -m venv <path-to-env>
    source <path-to-env>/bin/activate
    

    See the venv documentation for instructions on Windows.

    Note

    It is highly recommended to create a fresh environment when working with napari, to prevent issues with outdated or conflicting packages in your development environment.

  4. Install the package in editable mode, along with all of the developer tools.

    Note

    If you only want to use napari, you can install it on most macOS, Linux and Windows systems with Python 3.9-3.12 by following the directions on the instructions page.

    napari supports different Qt backends, and you can choose which one to install and use.

    For example, for PyQt5, the default, you would use the following:

    pip install -e ".[pyqt,dev]"  # (quotes only needed for zsh shell)
    

    If you want to use PySide2 instead, you would use:

    pip install -e ".[pyside,dev]"  # (quotes only needed for zsh shell)
    

    Finally, if you already have a Qt backend installed or want to use an experimental one like Qt6 use:

    pip install -e ".[dev]"  # (quotes only needed for zsh shell)
    

    Note that in this last case you will need to install your Qt backend separately.

  5. We use pre-commit to format code with black and lint with ruff automatically prior to each commit. To minimize test errors when submitting pull requests, please install pre-commit in your environment as follows:

    pre-commit install
    

    Upon committing, your code will be formatted according to our black configuration, which includes the settings skip-string-normalization = true and max-line-length = 79. To learn more, see black’s documentation.

    Code will also be linted to enforce the stylistic and logistical rules specified in our flake8 configuration, which currently ignores E203, E501, W503 and C901. For information on any specific flake8 error code, see the Flake8 Rules. You may also wish to refer to the PEP 8 style guide.

    If you wish to tell the linter to ignore a specific line use the # noqa comment along with the specific error code (e.g. import sys  # noqa: E402) but please do not ignore errors lightly.

Now you are all set to start developing with napari.