# Install extension module in built Slicer

**URL:** <https://discourse.slicer.org/t/install-extension-module-in-built-slicer/32032>\
**Category:** Development\
**Tags:** extensions\
**Created:** [October 4, 2023, 12:23pm UTC](https://discourse.slicer.org/t/install-extension-module-in-built-slicer/32032 "2023-10-04T12:23:39Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![park](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/park/32/5717_2.png) [@park](https://discourse.slicer.org/u/park)\
**Post date:** [October 4, 2023, 12:23pm UTC](https://discourse.slicer.org/t/install-extension-module-in-built-slicer/32032/1 "2023-10-04T12:23:39Z")

</div>

Hi all  
I’m having trouble installing an extension module in the built Slicer. Here is my situation:

- Slicer build was successful.

- I separately built the source code of the extension module from a Git repository, following the Developer guide for extesion, and it was successful.

- My current directory structure is as follows:

```auto
C:\D\S %slicer source
C:\D\SD %slicer build
C:\D\SlicerIGSIO %extesion source
C:\D\SlicerIGSIO-D %extesion build
C:\D\SlicerIGSIO-D\lib\Slicer-5.5
C:\D\SlicerIGT
C:\D\SlicerIGT-D
C:\D\SlicerOpenIGTLink
C:\D\SlicerOpenIGTLink-D

```

**In this situation, how can I make Slicer recognize modules like SlicerIGSIO-D, SlicerIGT-D and ETC ?**

\*(following option A) I try to find ‘SlicerWithMyExtension’ following the Developer guide for extesion but I can’t

\*(following option B) Moreover, I try to add the path to ‘Application setting’ but I could not find ‘qt-scripted-modules’ in ‘C:\D\SlicerIGSIO-D\lib\Slicer-5.5’ instruted in Developer guide

Should the extension module be included in the Slicer build process, or can it be separately built and then included?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [October 4, 2023, 1:49pm UTC](https://discourse.slicer.org/t/install-extension-module-in-built-slicer/32032/2 "2023-10-04T13:49:46Z")

</div>

The shell script below is and example of what I use when working with an extension that includes multiple c++ and python shared and loadable modules. This is for mac, but something similar should work on windows.

```auto
SLICER_BUILD=/opt/sr/Slicer-build
LIB_PATH=$(pwd)/inner-build/lib/Slicer-5.3

${SLICER_BUILD}/Slicer $* \
  --additional-module-paths \
    ${LIB_PATH}/cli-modules ${LIB_PATH}/qt-loadable-modules ${LIB_PATH}/qt-scripted-modules

```

---

<div class="post-metadata">

**Author:** ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)\
**Post date:** [October 4, 2023, 2:53pm UTC](https://discourse.slicer.org/t/install-extension-module-in-built-slicer/32032/3 "2023-10-04T14:53:35Z")

</div>

When I am debugging multiple extensions with third-party libraries, I combine the AdditionalLauncherSettings.ini files from each of the extensions into a single one, and launch Slicer/VisualStudio with that file (`--launcher-additional-settings GeneratedAdditionalSettings.ini`).

I created a python script to combine the files (copied [here](https://gist.github.com/Sunderlandkyl/f6b5fbf365a4cbf0935e4a89f4f38130)), but you can copy and paste to merge the ini together manually.

---

<div class="post-metadata">

**Author:** ![park](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/park/32/5717_2.png) [@park](https://discourse.slicer.org/u/park)\
**Post date:** [October 4, 2023, 3:33pm UTC](https://discourse.slicer.org/t/install-extension-module-in-built-slicer/32032/4 "2023-10-04T15:33:14Z")

</div>

Thank you for kind reply!

Then, is it correct that I need to make the following steps every time I edit the code in the extension module?

1. Edit somthing in extension
2. build extension
3. make ini from python
4. build slicer

Am I right ?

If it is right, could I ask about your development environment? (e.g., cmake, vscode or visual studio)

I try to use vscode because it it easy to make settings.json for cmake and running python

---

<div class="post-metadata">

**Author:** ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)\
**Post date:** [October 4, 2023, 3:41pm UTC](https://discourse.slicer.org/t/install-extension-module-in-built-slicer/32032/5 "2023-10-04T15:41:37Z")

</div>

You shouldn’t need to rebuild Slicer if you’re only editing the extension.

The ini also probably won’t need to be changed unless you

- a) Add a new extension that you want to use.  
or
- b) Modify the inclusion of ThirdParty libraries of an extension in CMake.

I use CMake and Visual Studio for compiling Slicer on Windows (see [Windows — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/windows.html)).

---

<div class="post-metadata">

**Author:** ![park](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/park/32/5717_2.png) [@park](https://discourse.slicer.org/u/park)\
**Post date:** [October 5, 2023, 2:04am UTC](https://discourse.slicer.org/t/install-extension-module-in-built-slicer/32032/6 "2023-10-05T02:04:54Z")

</div>

I am sorry for such a basic question.

I made .ini file follow your python code it is amazing !!

Then, I try to do command like this

```auto
C:\D\SD\Slicer-build>Slicer.exe --VisualStudio --launcher-additional-settings C:\D\SD\GeneratedSuperAdditionalLauncherSettings.ini

```

Is this right ?  
After the visual studio come up I try to build slicer then, turn on it again  
but I cannot find any changes …

---

<div class="post-metadata">

**Author:** ![park](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/park/32/5717_2.png) [@park](https://discourse.slicer.org/u/park)\
**Post date:** [October 5, 2023, 7:52am UTC](https://discourse.slicer.org/t/install-extension-module-in-built-slicer/32032/7 "2023-10-05T07:52:19Z")

</div>

Hi Kyle Sunderland  
I tried this also

```auto
C:\D\SD\Slicer-build>slicer --launcher-additional-settings C:\D\S\GeneratedSuperAdditionalLauncherSettings.ini

```

There is no error but nothing was changed , I cannot find extension modules in my slicer.

This is my .ini file. Is there something wrong ?

```auto
[General]
additionalpathvariables = PYTHONPATH

[LibraryPaths]
1\path = C:/D/SlicerIGSIO-D/inner-build/lib/Slicer-5.5/cli-modules/Debug
2\path = C:/D/SlicerIGSIO-D/inner-build/lib/Slicer-5.5/qt-loadable-modules/Debug
3\path = C:/D/SlicerIGSIO-D/lib/Slicer-5.5/Debug
4\path = C:/D/SlicerOpenIGTLink-D/inner-build/lib/Slicer-5.5/cli-modules/Debug
5\path = C:/D/SlicerOpenIGTLink-D/inner-build/lib/Slicer-5.5/qt-loadable-modules/Debug
6\path = C:/D/SlicerOpenIGTLink-D/lib/Slicer-5.5/Debug
7\path = C:/D/SlicerOpenIGTLink-D/OpenIGTLink-buildC:/D/SlicerOpenIGTLink-D/OpenIGTLink-build/bin/DebugC:/D/SlicerOpenIGTLink-D/binC:/D/SlicerOpenIGTLink-D/bin/Debug
8\path = C:/D/SlicerOpenIGTLink-D/OpenIGTLinkIO-buildC:/D/SlicerOpenIGTLink-D/OpenIGTLinkIO-build/bin/DebugC:/D/SlicerOpenIGTLink-D/binC:/D/SlicerOpenIGTLink-D/bin/Debug
size = 8

[Paths]
1\path = C:/D/SlicerIGSIO-D/inner-build/lib/Slicer-5.5/cli-modules/Debug
2\path = C:/D/SlicerIGSIO-D/inner-build/bin/Debug
3\path = C:/D/SlicerIGSIO-D/bin/Debug
4\path = C:/D/SlicerIGSIO-D/VP9/
5\path = C:/D/SlicerOpenIGTLink-D/inner-build/lib/Slicer-5.5/cli-modules/Debug
6\path = C:/D/SlicerOpenIGTLink-D/inner-build/bin/Debug
7\path = C:/D/SlicerOpenIGTLink-D/bin/Debug
size = 7

[EnvironmentVariables]

[PYTHONPATH]
1\path = C:/D/SlicerIGSIO-D/inner-build/lib/Slicer-5.5/qt-scripted-modules
2\path = C:/D/SlicerIGSIO-D/inner-build/lib/Slicer-5.5/qt-loadable-modules/Debug
3\path = C:/D/SlicerIGSIO-D/inner-build/lib/Slicer-5.5/qt-loadable-modules/Python
4\path = C:/D/SlicerIGSIO-D/lib/Slicer-5.5/Debug
5\path = C:/D/SlicerOpenIGTLink-D/inner-build/lib/Slicer-5.5/qt-scripted-modules
6\path = C:/D/SlicerOpenIGTLink-D/inner-build/lib/Slicer-5.5/qt-loadable-modules/Debug
7\path = C:/D/SlicerOpenIGTLink-D/inner-build/lib/Slicer-5.5/qt-loadable-modules/Python
8\path = C:/D/SlicerOpenIGTLink-D/lib/Slicer-5.5/Debug
size = 8

```

---

<div class="post-metadata">

**Author:** ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)\
**Post date:** [October 5, 2023, 2:00pm UTC](https://discourse.slicer.org/t/install-extension-module-in-built-slicer/32032/8 "2023-10-05T14:00:33Z")

</div>

You also still need to include `--additional-module-paths` when launching Slicer, pointing to the qt-loadable-modules/Debug, qt-scripted-modules and cli-modules/Debug for each of the extensions.

---

<div class="post-metadata">

**Author:** ![park](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/park/32/5717_2.png) [@park](https://discourse.slicer.org/u/park)\
**Post date:** [October 5, 2023, 4:11pm UTC](https://discourse.slicer.org/t/install-extension-module-in-built-slicer/32032/9 "2023-10-05T16:11:25Z")

</div>

You mean… in commend line?

I really appreciate if you provide to me the example of your commend line and .ini  
Then I can follow you

---

<div class="post-metadata">

**Author:** ![Sunderlandkyl](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sunderlandkyl/32/79987_2.png) [@Sunderlandkyl](https://discourse.slicer.org/u/Sunderlandkyl)\
**Post date:** [October 5, 2023, 4:21pm UTC](https://discourse.slicer.org/t/install-extension-module-in-built-slicer/32032/10 "2023-10-05T16:21:01Z")

</div>

Yes, in command line, something like:

```auto
"C:/d/s/S4W/Slicer-build/Slicer.exe" --launcher-additional-settings "C:d/s/GeneratedSuperAdditionalLauncherSettings.ini --additional-module-paths "C:\d\s\SIGSIOW\inner-build\lib\Slicer-5.5\qt-loadable-modules\RelWithDebInfo" "C:\d\s\SOIGTLW\inner-build\lib\Slicer-5.5\qt-loadable-modules\RelWithDebInfo" "C:\d\s\SOIGTLW\inner-build\lib\Slicer-5.5\qt-scripted-modules" "C:\d\s\SIGTW\lib\Slicer-5.5\qt-loadable-modules\RelWithDebInfo" "C:\d\s\SIGTW\lib\Slicer-5.5\qt-scripted-modules"

```

---

<div class="post-metadata">

**Author:** ![park](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/park/32/5717_2.png) [@park](https://discourse.slicer.org/u/park)\
**Post date:** [October 7, 2023, 2:53am UTC](https://discourse.slicer.org/t/install-extension-module-in-built-slicer/32032/11 "2023-10-07T02:53:58Z")

</div>

Thank you Kyle !

I sovled the problem!

Then I made a python code the to run Slicer with .ini setting  
automatically consider additional path setting

```auto
import subprocess
import configparser

paths = []
config = configparser.ConfigParser()
config.read('C:/D3/S/GeneratedSuperAdditionalLauncherSettings.ini')

# Check if the 'Paths' section exists in the INI file
if 'Paths' in config:
    paths_section = config['PYTHONPATH']

    # Get all the keys in the 'Paths' section
    path_keys = paths_section.keys()

    # Iterate through the keys and print the corresponding values
    for key in path_keys:
        if key != 'size': # Exclude the 'size' key
            path_value = paths_section[key]
            paths.append(path_value)

command = [
    "C:/D3/SR/Slicer-build/Slicer.exe",
    
    "--launcher-additional-settings",
    "C:/D3/S/GeneratedSuperAdditionalLauncherSettings.ini",
    
    "--additional-module-paths",
]+paths

subprocess.run(command)

```
