Improved python package installation: slicer.packaging

An improved python package installation experience is now available out of the box for extension developers: slicer.packaging.

This feature was merged about a month ago and is available in the preview version of Slicer.

The existing slicer.util.pip_install has been expanded in functionality to support a more interactive experience: a GUI like the one shown below when blocking, or the possibility to run without blocking the application.

Additionally, new functions have been added:

Function Purpose
slicer.packaging.load_requirements(path) Parse a requirements.txt into Requirement objects.
slicer.packaging.load_pyproject_dependencies(path) Parse [project.dependencies] from a pyproject.toml
slicer.packaging.pip_check(reqs) Are the requirements already satisfied?
slicer.packaging.pip_install(...) Install, with various modes and hooks.
slicer.packaging.pip_ensure(reqs, requester="...") High-level workflow: check, prompt, install with progress, and offer restart if needed.

The bottom line for extension developers is: Use slicer.packaging.pip_ensure! If you need lower level control, you can instead use slicer.packaging.pip_check and slicer.packaging.pip_install directly.

See the following for more details: