### Launch Slicer and load a file using 'start' command Source: https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html Uses the 'start' command to launch the most recently installed Slicer and load an image file. This is a Windows-specific shortcut. ```bash start Slicer c:\\some\\folder\\MRHead.nrrd ``` -------------------------------- ### Install Qt 5 Components via Command Line Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/linux.html Install specific Qt 5 components using the online installer. Ensure your qt.io account credentials are set as environment variables. ```bash export QT_ACCOUNT_LOGIN= export QT_ACCOUNT_PASSWORD= ./qt-online-installer-linux-x64-online.run \ install \ qt.qt5.5152.gcc_64 \ qt.qt5.5152.qtwebengine \ qt.qt5.5152.qtwebengine.gcc_64 \ --root /opt/qt \ --email $QT_ACCOUNT_LOGIN \ --pw $QT_ACCOUNT_PASSWORD ``` -------------------------------- ### Install Qt 6 Components via Command Line Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/linux.html Install specific Qt 6 components using the online installer. Ensure your qt.io account credentials are set as environment variables. ```bash export QT_ACCOUNT_LOGIN= export QT_ACCOUNT_PASSWORD= ./qt-online-installer-linux-x64-online.run \ install \ qt.qt6.680.gcc_64 \ qt.qt6.680.addons.qtwebengine \ qt.qt6.680.addons.qt5compat \ --root /opt/qt \ --email $QT_ACCOUNT_LOGIN \ --pw $QT_ACCOUNT_PASSWORD ``` -------------------------------- ### Example: Multiple Registration Methods Source: https://slicer.readthedocs.io/en/latest/user_guide/modules/brainsfit.html Chain multiple registration methods in a comma-separated list to progressively refine the alignment. The order matters, starting with simpler transforms and moving to more complex ones. ```bash --transformType Rigid,ScaleVersor3D,ScaleSkewVersor3D,Affine,BSpline \ ``` -------------------------------- ### Download and Make Qt Installer Executable Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/linux.html Download the Qt Linux online installer and set execute permissions for it. ```bash curl -LO https://download.qt.io/official_releases/online_installers/qt-online-installer-linux-x64-online.run chmod +x qt-online-installer-linux-x64-online.run ``` -------------------------------- ### Verify Qt6 Installation Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/macos.html After installing Qt6, use this command to verify that it has been correctly installed and is accessible in your environment. ```bash qmake --version ``` -------------------------------- ### Setup Slicer Development Environment Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/macos.html Navigate into the cloned Slicer directory and run the setup script to prepare the development environment. ```bash cd Slicer ./Utilities/SetupForDevelopment.sh ``` -------------------------------- ### Install Extension from Server Source: https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html Downloads and installs a Slicer extension from the server. Set `interactive` to `False` to prevent popups. The `restart` parameter controls whether Slicer should restart after installation. ```Python extensionName = 'SlicerIGT' em = slicer.app.extensionsManagerModel() em.interactive = False # prevent display of popups restart = True if not em.installExtensionFromServer(extensionName, restart): raise ValueError(f"Failed to install {extensionName} extension") ``` -------------------------------- ### Install Python Package with Progress Dialog Source: https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html Use pip_install for direct installation with visual feedback. This function now shows a progress dialog by default, providing a better user experience than simple installation. ```python try: import flywheel except ModuleNotFoundError: if slicer.util.confirmOkCancelDisplay("This module requires 'flywheel-sdk' Python package. Click OK to install it now."): slicer.packaging.pip_install("flywheel-sdk", requester="MyModule") import flywheel ``` -------------------------------- ### Install Qt6 and Configure Environment Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/macos.html These commands install Qt6 using Homebrew and then configure your shell environment to use the newly installed Qt6 by adding it to the PATH and CMAKE_PREFIX_PATH. The shell is then reloaded to apply these changes. ```bash brew install qt@6 #Add Qt6 to shell environment echo 'export PATH="/opt/homebrew/opt/qt@6/bin:$PATH"' >> ~/.zshrc echo 'export CMAKE_PREFIX_PATH="/opt/homebrew/opt/qt@6:$CMAKE_PREFIX_PATH"' >> ~/.zshrc #Reload shell source ~/.zshrc ``` -------------------------------- ### Install Ubuntu 25.10 Prerequisites for Qt 5 Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/linux.html Installs necessary development tools and Qt 5 support libraries for building Slicer on Ubuntu 25.10. ```bash sudo apt update && sudo apt install git git-lfs build-essential \ libqt5x11extras5-dev qtmultimedia5-dev libqt5svg5-dev qtwebengine5-dev libqt5xmlpatterns5-dev qttools5-dev qtbase5-private-dev \ libxt-dev ``` -------------------------------- ### Configure Slicer Build with Qt6 from Online Installer Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/linux.html Specify the Qt6_DIR path when Qt6 is installed from the Qt Company online installer. ```bash cmake \ -DCMAKE_BUILD_TYPE:STRING=Release \ -DQt6_DIR:PATH=/opt/qt/6.8.0/gcc_64/lib/cmake/Qt6 \ ../Slicer ``` -------------------------------- ### Install Python Packages with Progress Dialog in Slicer Source: https://slicer.readthedocs.io/en/latest/developer_guide/python_faq.html Use slicer.packaging.pip_install with show_progress=True for direct package installation, displaying a modal progress dialog to the user. This is useful for providing visual feedback during installation. ```python slicer.packaging.pip_install(show_progress=True) ``` -------------------------------- ### Install Qt 5 Dev Tools on Ubuntu 22.04 Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/linux.html Installs development tools and Qt 5 support libraries for building Slicer on Ubuntu 22.04. ```bash sudo apt update && sudo apt install git build-essential cmake cmake-curses-gui cmake-qt-gui \ libqt5x11extras5-dev qtmultimedia5-dev libqt5svg5-dev qtwebengine5-dev libqt5xmlpatterns5-dev qttools5-dev qtbase5-private-dev \ libxt-dev libssl-dev ``` -------------------------------- ### Registering Nodes and Plugins in Module Setup Source: https://slicer.readthedocs.io/en/latest/developer_guide/mrml_overview.html In the module's CXX file, override the setup() function to register displayable managers, subject hierarchy plugins, and I/O handlers. Also, specify associated node types. ```c++ // In qSlicerModule.cxx: void setup() { // Register displayable managers vtkMRMLThreeDViewDisplayableManagerFactory::GetInstance()->RegisterDisplayableManager(...); vtkMRMLSliceViewDisplayableManagerFactory::GetInstance()->RegisterDisplayableManager(...); // Register subject hierarchy plugin qSlicerSubjectHierarchyPluginHandler::GetInstance()->RegisterPlugin(...); // Register reader and writer qSlicerIOManager::GetInstance()->RegisterIOHandler(...); } QStringList associatedNodeTypes() const { // Return all new MRML classes (data, display, storage) return QStringList() << "vtkMRMLNode" << "vtkMRMLDisplayNode" << "vtkMRMLStorageNode"; } ``` -------------------------------- ### Full BRAINSFit Command Example Source: https://slicer.readthedocs.io/en/latest/user_guide/modules/brainsfit.html A complete command-line example demonstrating longitudinal registration of same-subject T1 scans, including all previously specified parameters. ```bash BRAINSFit --fixedVolume test.nii.gz \ --movingVolume test2.nii.gz \ --outputVolume testT1LongRegFixed.nii.gz \ --outputTransform longToBase.xform \ --transformType Rigid \ --histogramMatch \ --initializeTransformMode useCenterOfHeadAlign \ --maskProcessingMode ROIAUTO \ --ROIAutoDilateSize 3 \ --interpolationMode Linear ``` -------------------------------- ### Install Debian 12 Prerequisites for Qt 5 Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/linux.html Installs necessary development tools and Qt 5 support libraries for building Slicer on Debian 12. ```bash sudo apt update && sudo apt install git build-essential cmake cmake-curses-gui cmake-qt-gui \ qtmultimedia5-dev qttools5-dev libqt5xmlpatterns5-dev libqt5svg5-dev qtwebengine5-dev qtscript5-dev \ qtbase5-private-dev libqt5x11extras5-dev libxt-dev libssl-dev ``` -------------------------------- ### Install ffmpeg on Linux Source: https://slicer.readthedocs.io/en/latest/user_guide/modules/screencapture.html Compile and install ffmpeg from source on Linux systems. This method allows for custom build configurations. ```bash git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg cd ffmpeg sudo apt-get install libx264-dev ./configure --enable-gpl --enable-libx264 --prefix=${HOME} make install ``` -------------------------------- ### Install Xcode Command Line Tools Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/macos.html Install the necessary command line tools for Xcode. This is a prerequisite for building Slicer on macOS. ```bash xcode-select --install ``` -------------------------------- ### Install Homebrew Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/macos.html Execute this command to install Homebrew, a package manager for macOS, which is a prerequisite for managing other development tools and libraries. ```bash $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` -------------------------------- ### Verify Xcode Installation Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/macos.html Checks the installed version of Xcode and the active developer directory path. This helps confirm that Xcode is set up correctly. ```bash xcodebuild -version xcode-select -p ``` -------------------------------- ### Install System Dependencies for Qt 6 on Ubuntu 22.04 Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/linux.html Installs system dependencies required for building Slicer with Qt 6 on Ubuntu 22.04. Note that Ubuntu 22.04 ships with Qt 6.2.4, which is below the officially supported minimum. Qt 6.8 or later must be installed separately. ```bash sudo apt update && sudo apt install git build-essential cmake cmake-curses-gui cmake-qt-gui \ libxt-dev libssl-dev ``` -------------------------------- ### Install Xcode Command Line Tools Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/macos.html Run this command in the terminal to install the necessary Xcode command line tools on macOS, which are required for certain build processes like PCRE configuration. ```bash xcode-select --install ``` -------------------------------- ### Load Requirements from File and Ensure Installation Source: https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html Load package requirements from a `requirements.txt` file using `load_requirements()` and then ensure their installation with `pip_ensure`. This is useful for managing dependencies defined in a project's resource path. ```python reqs = slicer.packaging.load_requirements(self.resourcePath("requirements.txt")) slicer.packaging.pip_ensure(reqs, requester="MyFilter") ``` -------------------------------- ### Check if Pip Install is in Progress Source: https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html Use this to check if a non-blocking pip installation is currently running before starting an operation that might conflict. Returns true if an installation is in progress, false otherwise. ```python if slicer.packaging.isPipInstallInProgress(): slicer.util.warningDisplay( "Package installation is in progress. Please wait." ) else: slicer.packaging.pip_install("scipy", blocking=False) ``` -------------------------------- ### slicer.packaging.isPipInstallInProgress Source: https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html Check if a non-blocking pip install is currently in progress. Use this to check before starting an operation that might conflict with an ongoing pip installation. ```APIDOC ## slicer.packaging.isPipInstallInProgress() ### Description Check if a non-blocking pip install is currently in progress. Use this to check before starting an operation that might conflict with an ongoing pip installation. ### Returns - **bool**: True if a non-blocking pip install is in progress, False otherwise. ### Example ```python if slicer.packaging.isPipInstallInProgress(): slicer.util.warningDisplay( "Package installation is in progress. Please wait." ) else: slicer.packaging.pip_install("scipy", blocking=False) ``` ``` -------------------------------- ### Example successful output for GET /volumes, GET /gridtransforms Source: https://slicer.readthedocs.io/en/latest/user_guide/modules/webserver.html This JSON structure represents the expected output when retrieving a list of volume or grid transform node names and IDs. ```json [ {"name": "Volume1", "id": "vtkMRMLScalarVolumeNode1"}, {"name": "Volume2", "id": "vtkMRMLScalarVolumeNode2"}, ] ``` -------------------------------- ### Get Segment Centroid in World Coordinates Source: https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html This example shows how to get the centroid of a segment in world (RAS) coordinates. It calculates the mean of non-zero voxel coordinates and converts them to world space. ```python segmentationNode = getNode("Segmentation") segmentId = "Segment_1" # Get array voxel coordinates import numpy as np seg = slicer.util.arrayFromSegmentBinaryLabelmap(segmentationNode, segmentId) # numpy array has voxel coordinates in reverse order (KJI instead of IJK) # and the array is cropped to minimum size in the segmentation mean_KjiCropped = [coords.mean() for coords in np.nonzero(seg)] # Get segmentation voxel coordinates segImage = slicer.vtkOrientedImageData() segmentationNode.GetBinaryLabelmapRepresentation(segmentId, segImage) segImageExtent = segImage.GetExtent() # origin of the array in voxel coordinates is determined by the start extent mean_Ijk = [mean_KjiCropped[2], mean_KjiCropped[1], mean_KjiCropped[0]] + np.array([segImageExtent[0], segImageExtent[2], segImageExtent[4]]) ``` -------------------------------- ### macOS System and Tool Information Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/macos.html This example shows how to display system information on macOS, including the operating system version, QMake version, CMake version, and hardware details. This is useful for documenting the build environment. ```bash frolick@IsabelMacBook % sw_vers ProductName: macOS ProductVersion: 15.7.3 BuildVersion: 24G419 frolick@IsabelMacBook % qmake --version QMake version 3.1 Using Qt version 6.10.1 in /opt/homebrew/lib frolick@IsabelMacBook % cmake --version cmake version 3.31.5 CMake suite maintained and supported by Kitware (kitware.com/cmake). frolick@IsabelMacBook % system_profiler SPHardwareDataType Hardware: Hardware Overview: Model Name: MacBook Pro Model Identifier: Mac15,6 Chip: Apple M3 Pro Total Number of Cores: 11 (5 performance and 6 efficiency) Memory: 36 GB ``` -------------------------------- ### slicer.util.getFirstNodeByName() Source: https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html Gets the first MRML node whose name starts with a specified prefix, optionally filtering by class name. ```APIDOC ## slicer.util.getFirstNodeByName(_name_, _className =None_) ### Description Get the first MRML node that name starts with the specified name. Optionally specify a classname that must also match. ### Method Python Function Call ### Endpoint slicer.util.getFirstNodeByName(_name_, _className =None_) ### Parameters #### Path Parameters - **_name_** (string) - Required - The prefix of the node name to search for. - **_className** (string) - Optional - The class name that the node must also match. ``` -------------------------------- ### Example Qt Command-Line Option: Display Source: https://slicer.readthedocs.io/en/latest/user_guide/settings.html The -display option allows switching displays on X11 and overrides the DISPLAY environment variable. ```bash -display hostname:screen_number ``` -------------------------------- ### Example successful output for GET /fiducials Source: https://slicer.readthedocs.io/en/latest/user_guide/modules/webserver.html This JSON structure shows the expected output when retrieving basic information about markup point lists in the scene. ```json { "vtkMRMLMarkupsFiducialNode1": { "name": "F", "color": [1.0, 0.5000076295109483, 0.5000076295109483], "scale": 3.0, "markups": [ {"label": "F-1", "position": [-35.422643698898014, 13.121414583492907, -10.214302062988281]}, {"label": "F-2", "position": [43.217879176918984, 41.565859027937364, -10.214302062988281]}, {"label": "F-3", "position": [39.8714739481608, -32.05505600474238, -10.214302062988281]} ]}, "vtkMRMLMarkupsFiducialNode2": { "name": "F_1", "color": [1.0, 0.5000076295109483, 0.5000076295109483], "scale": 3.0, "markups": [ {"label": "F_1-1", "position": [82.53814061482748, 13.121414583492907, -23.599922978020956]}, {"label": "F_1-2", "position": [-4.468395332884938, 13.121414583492907, 65.07981558407056]} ]} } ``` -------------------------------- ### Override Application Close Behavior Source: https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html Customize the application's close behavior by installing an event filter. This example demonstrates how to suppress the default confirmation popup when the application is closing. ```python class CloseApplicationEventFilter(qt.QWidget): def eventFilter(self, object, event): if event.type() == qt.QEvent.Close: event.accept() return True return False filter = CloseApplicationEventFilter() slicer.util.mainWindow().installEventFilter(filter) ``` -------------------------------- ### Example Qt Command-Line Option: DPI Awareness Source: https://slicer.readthedocs.io/en/latest/user_guide/settings.html Use the -platform windows:dpiawareness option to control DPI awareness settings on Windows. ```bash -platform windows:dpiawareness=[0|1|2] ``` -------------------------------- ### Get Displayable Manager for a View Source: https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html This example demonstrates how to retrieve a specific displayable manager, such as the model displayable manager, for a given 3D view node. Displayable managers are responsible for rendering MRML nodes into VTK actors. ```python threeDViewNode = slicer.mrmlScene.GetNodeByID("vtkMRMLViewNode1") appLogic = slicer.app.applicationLogic() modelDisplayableManager = appLogic.GetViewDisplayableManagerByClassName(threeDViewNode, "vtkMRMLModelDisplayableManager") if modelDisplayableManager is None: logging.error("Failed to find the model displayable manager") ``` -------------------------------- ### setup Source: https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html Initializes the scripted module. This method is typically called when the module is loaded. ```APIDOC ## setup() ### Description Initializes the scripted module. ### Method (Implicitly a method call within the Slicer environment) ``` -------------------------------- ### Example Qt Command-Line Option: Window Geometry Source: https://slicer.readthedocs.io/en/latest/user_guide/settings.html Use the -qwindowgeometry option to specify the initial size and position of the main Slicer window using X11 syntax. ```bash -qwindowgeometry 100x100+50+50 ``` -------------------------------- ### slicer.packaging.pip_ensure Source: https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html Ensures that specified Python packages are installed and available. It handles user prompts for installation and restart if necessary. This is the recommended function for installing packages required by modules. ```APIDOC ## slicer.packaging.pip_ensure ### Description Ensures that specified Python packages are installed and available. It handles user prompts for installation and restart if necessary. This is the recommended function for installing packages required by modules. ### Parameters * **requirements** – Requirement(s) to ensure. Accepts a space-separated string (e.g., `"flywheel-sdk>=1.0 numpy"`), a single `Requirement`, or a list of strings and/or Requirement objects. Can also be obtained from `load_requirements()` or `load_pyproject_dependencies()`. * **constraints** – Path to a constraints file (string or Path object), or None. When provided, passed to pip as `-c constraints.txt` during installation. Constraints files use the same format as requirements files but only constrain versions without triggering installation. Useful for ensuring compatible versions across multiple extensions. * **skip_packages** – Discouraged workaround for transitive dependency conflicts; see the script repository for guidance. Forwarded to `pip_install()`. * **prompt_install** – If True (default), show confirmation dialog before installing. * **prompt_restart** – If True (default), check whether any updated packages were already imported and, if so, show a dialog recommending a restart. The user can choose to restart immediately or continue without restarting. * **requester** – Name shown in dialog to identify who is requesting the packages (e.g., “TotalSegmentator”, “MyFilter”, “MyExtension”). * **skip_in_testing** – If True (default), skip installation when Slicer is running in testing mode (`slicer.app.testingEnabled()`). This prevents tests from modifying the Python environment. Set to False if your test explicitly needs to verify installation behavior. * **show_progress** – If True (default), show progress dialog during installation with status updates and collapsible log details. If False, show only a busy cursor during installation. ### Returns When `skip_packages` is provided, a list of skipped requirement strings (forwarded from `pip_install()`). Otherwise `None`. ### Raises * **RuntimeError** – If user declines installation. * **subprocess.CalledProcessError** – If installation fails. ### Request Example ```python class MyFilterWidget(ScriptedLoadableModuleWidget): def onApplyButton(self): slicer.packaging.pip_ensure("scikit-image>=0.20", requester="MyFilter") import skimage # Now safe to use skimage filtered = skimage.filters.gaussian(array, sigma=2.0) ``` For loading from a requirements file, use `load_requirements()`: ```python reqs = slicer.packaging.load_requirements(self.resourcePath("requirements.txt")) slicer.packaging.pip_ensure(reqs, requester="MyFilter") ``` For more examples (constraints, skip_packages), see Script repository (Python package management section). ``` -------------------------------- ### Create Custom Web Server Instance Source: https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html This script demonstrates how to create a custom web server instance to serve static content from a specified directory on a given port. Use with caution, especially on untrusted networks. ```python import WebServer import WebServerLib # serve content from the temp directory on port 9916 and print all messages handler = WebServerLib.StaticPagesRequestHandler(docroot=b"/tmp", logMessage=print) logic = WebServer.WebServerLogic(port=9916, requestHandlers=[handler], logMessage=print) logic.start() print(f"Open 'http://localhost:{logic.port}'") # stop later with logic.stop() ``` -------------------------------- ### Install Python Packages with pip_install Source: https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html Use `pip_install` to directly install Python packages. This method is a wrapper around `python -m pip install` and is recommended over direct pip calls for future compatibility and potential Slicer-specific optimizations. It supports specifying requirements, constraints, and packages to install without dependencies. ```python slicer.packaging.pip_install(_requirements : str | list[str]_, _constraints : str | Path | None = None_, _no_deps_requirements : str | list[str] | None = None_, _skip_packages : list[str] | None = None_, _blocking : bool = True_, _show_progress : bool = True_, _requester : str | None = None_, _parent : qt.QWidget | None = None_, _logCallback : Callable[[str], None] | None = None_, _completedCallback : Callable[[int], None] | None = None_) → list[str] | None ``` -------------------------------- ### Install Python Packages with Constraints File (pip_install) Source: https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html Use pip_install with a constraints file for lower-level control over package installation. This method is useful when you need to specify constraints directly during the installation process. ```python # Via pip_install (lower level) slicer.packaging.pip_install("pandas scipy", constraints="/path/to/constraints.txt") ``` -------------------------------- ### Install Python Packages with pip_install Source: https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html Installs Python packages using pip. Supports various options like skipping packages and non-blocking installations. Refer to the script repository for advanced usage. ```python pip_install("pandas scipy scikit-learn") ``` -------------------------------- ### Install, Upgrade, and Uninstall Slicer with Homebrew Source: https://slicer.readthedocs.io/en/latest/user_guide/getting_started.html Use these commands to manage Slicer installations via the Homebrew package manager on macOS. This method simplifies the installation process compared to manual downloads. ```bash brew install --cask slicer # to install brew upgrade slicer # to upgrade brew uninstall slicer # to uninstall ``` -------------------------------- ### Launch Qt Creator on Windows Source: https://slicer.readthedocs.io/en/latest/developer_guide/debugging/qtcreatorcpp.html Launch Qt Creator from the command prompt within the Slicer build directory to set up the environment for designing UIs with CTK and Slicer custom designer plugins. ```batch cd c:\path\to\Slicer-Superbuild\Slicer-build .\Slicer.exe --launch /path/to/qtcreator.exe ``` -------------------------------- ### Install Python Packages Source: https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html Installs Python packages using pip. This is a wrapper for `slicer.packaging.pip_install()`. ```python slicer.util.pip_install("numpy") ``` -------------------------------- ### Example Extension Catalog Entry File Source: https://slicer.readthedocs.io/en/latest/developer_guide/extensions.html This JSON file describes how to build and package a Slicer extension, including category, source code URL, and build dependencies. ```json { "name": "MyExtension", "version": "1.0.0", "category": "Visualization", "scm_url": "https://github.com/MyOrg/MyExtension.git", "scm_revision": "main", "build_dependencies": [ "ExtensionA", "ExtensionB" ], "dicom_support_rule": "Modality == 'PT' or Modality == 'RWVM'", "enabled": true } ``` -------------------------------- ### Prepare and Execute Build Script Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/macos.html Navigates to the superbuild directory, makes the build script executable, and then runs it to compile Slicer. ```bash cd /opt/scmake chmod +x ./build_slicer.sh ./build_slicer.sh ``` -------------------------------- ### Ensure Package Installation with Slicer Source: https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html Use `pip_ensure` to install a package and its dependencies. A restart prompt may appear if updated packages were already imported. Specify the `requester` to identify the source of the installation request. ```python class MyFilterWidget(ScriptedLoadableModuleWidget): def onApplyButton(self): slicer.packaging.pip_ensure("scikit-image>=0.20", requester="MyFilter") import skimage # Now safe to use skimage filtered = skimage.filters.gaussian(array, sigma=2.0) ``` -------------------------------- ### Install Ubuntu 25.10 Prerequisites for Qt 6 Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/linux.html Installs necessary development tools and Qt 6 support libraries for building Slicer on Ubuntu 25.10. Ubuntu 25.10 ships Qt 6.9.2, which meets the minimum requirement. ```bash sudo apt update && sudo apt install git git-lfs build-essential \ qt6-base-dev qt6-base-private-dev qt6-multimedia-dev qt6-tools-dev qt6-tools-dev-tools \ qt6-svg-dev qt6-5compat-dev qt6-webengine-dev qt6-webengine-dev-tools qt6-scxml-dev \ libxt-dev libssl-dev ``` -------------------------------- ### Non-blocking Package Installation with Callback Source: https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html Install packages without blocking the UI by setting `blocking=False`. A `completedCallback` function can be provided to handle post-installation logic, such as importing newly installed modules or displaying error messages. ```python def onComplete(returnCode): if returnCode == 0: import pandas # Now safe to import else: slicer.util.errorDisplay("Failed to install packages") slicer.packaging.pip_install( "pandas scipy", blocking=False, completedCallback=onComplete, ) # Returns immediately — UI stays responsive ``` -------------------------------- ### Example Extension Description File Syntax Source: https://slicer.readthedocs.io/en/latest/developer_guide/extensions.html Illustrates the syntax for comments, metadata, and values in an extension description file (.s4ext). Supports key-value pairs and comments. ```text # This is a comment metadataname This is the value associated with 'metadataname' # This is an other comment anothermetadata This is the value associated with 'anothermetadata' ``` -------------------------------- ### Build Slicer Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/macos.html Start the build process for Slicer. Navigate to the build directory (/opt/s) and use 'make -j' followed by the number of processor cores to speed up compilation. You can find the number of available cores by running 'sysctl -n hw.ncpu'. ```bash cd ~/opt/s make -j4 ``` -------------------------------- ### Install Package Without Declared Dependencies Source: https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html Use `no_deps_requirements` to install a package while bypassing its declared dependencies, allowing for manual installation of compatible versions. This is useful when a package has overly strict or conflicting dependency declarations. ```python slicer.packaging.pip_install( requirements="numpy scipy", no_deps_requirements="problematic-pkg==1.0", ) ``` -------------------------------- ### setupDeveloperSection Source: https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html Sets up the developer-specific section of the scripted module's user interface. ```APIDOC ## setupDeveloperSection() ### Description Sets up the developer section for the scripted module. ### Method (Implicitly a method call within the Slicer environment) ``` -------------------------------- ### Ensure Python Package Installation with Slicer Source: https://slicer.readthedocs.io/en/latest/developer_guide/python_faq.html Use slicer.packaging.pip_ensure to manage Python package dependencies for your Slicer module. This function checks, prompts the user, and installs packages as needed, skipping installation in testing mode. ```python slicer.packaging.pip_ensure() ``` -------------------------------- ### Install ffmpeg on macOS Source: https://slicer.readthedocs.io/en/latest/user_guide/modules/screencapture.html Use Homebrew to install the ffmpeg library on macOS. This is required for video export functionality. ```bash brew install ffmpeg ``` -------------------------------- ### Install Debian 12 Prerequisites for Qt 6 Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/linux.html Installs necessary development tools and Qt 6 support libraries for building Slicer on Debian 12. Note that Debian 12's Qt 6.4.2 is below the officially supported minimum of 6.8, and may require explicit version configuration. ```bash sudo apt update && sudo apt install git build-essential cmake-curses-gui cmake-qt-gui \ qt6-base-dev qt6-base-private-dev qt6-multimedia-dev qt6-tools-dev \ qt6-svg-dev qt6-5compat-dev qt6-webengine-dev qt6-webengine-dev-tools qt6-scxml-dev \ libxt-dev libssl-dev ``` -------------------------------- ### slicer.util.startQtDesigner Source: https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html Starts the Qt Designer application, allowing for the editing of UI files. ```APIDOC ## slicer.util.startQtDesigner ### Description Start Qt Designer application to allow editing UI files. ### Method `slicer.util.startQtDesigner(_args =None_)` ``` -------------------------------- ### Simple Python Package Installation (No Progress) Source: https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html Use pip_install with show_progress=False for scripting or automation where visual feedback is not needed. This is a lower-level function that bypasses the progress dialog. ```python try: import flywheel except ModuleNotFoundError: if slicer.util.confirmOkCancelDisplay("This module requires 'flywheel-sdk' Python package. Click OK to install it now."): slicer.packaging.pip_install("flywheel-sdk", show_progress=False) import flywheel ``` -------------------------------- ### Install Dependencies on Fedora Source: https://slicer.readthedocs.io/en/latest/user_guide/getting_started.html Installs necessary libraries for 3D Slicer on Fedora systems. Ensure your system is up-to-date before running. ```bash sudo dnf install mesa-libGLU mesa-libGL libnsl libXrender pulseaudio-libs-glib2 nss libXcomposite libXdamage libXrandr ftgl libXcursor libXi libXtst alsa-lib qt5-qtx11extras ``` -------------------------------- ### Install Qt 6 Dev Tools on Ubuntu 24.04 Source: https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/linux.html Installs development tools and Qt 6 support libraries for building Slicer on Ubuntu 24.04. Note that Ubuntu 24.04 ships with Qt 6.4.2, which is below the officially supported minimum. A manual override for the Qt version check might be necessary. ```bash sudo apt update && sudo apt install git git-lfs build-essential \ qt6-base-dev qt6-base-private-dev qt6-multimedia-dev qt6-tools-dev \ qt6-svg-dev qt6-5compat-dev qt6-webengine-dev qt6-webengine-dev-tools qt6-scxml-dev \ libxt-dev libssl-dev ```