# Installing Slicer extension from script

**URL:** https://discourse.slicer.org/t/installing-slicer-extension-from-script/25241
**Category:** Development
**Created:** [September 13, 2022, 4:13pm UTC](https://discourse.slicer.org/t/installing-slicer-extension-from-script/25241 "2022-09-13T16:13:24Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Nadya\_Shusharina](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/nadya_shusharina/32/9186_2.png) [@Nadya\_Shusharina](https://discourse.slicer.org/u/Nadya_Shusharina)
#### Post date: [September 13, 2022, 4:13pm UTC](https://discourse.slicer.org/t/installing-slicer-extension-from-script/25241/1 "2022-09-13T16:13:24Z")

</div>

Hello,  
I would like to build a Docker container with Slicer 5.0.2 r30822 linux-amd64, and with Slicer extensions installed. To do that, I am trying to have Slicer install extensions from a python script:

```auto
emm = slicer.app.extensionsManagerModel()
md = emm.retrieveExtensionMetadataByName("DCMQI")
x = emm.downloadAndInstallExtension(md['extension_id'])
if x:
    print('emm completed ok')
else:
    print('emm error', x)

```

and then run `Slicer --python-script "myscript.py" --no-splash --no-main-window`  
This does download and install the extension but the script does not exit. If I add `sys.exit(0)` to the script as suggested [here](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html), Slicer exits after downloading the extension, but before installing it. Could you please advise what is the correct way to install Slicer extensions from script?

Thank you,  
Nadya

---

<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: [September 13, 2022, 5:14pm UTC](https://discourse.slicer.org/t/installing-slicer-extension-from-script/25241/2 "2022-09-13T17:14:41Z")

</div>

Here’s an example of installing extensions in a dockerfile with a python script:

> **[SlicerDockers/slicer-plus at master · pieper/SlicerDockers](https://github.com/pieper/SlicerDockers/tree/master/slicer-plus)**
>
> master/slicer-plus

---

<div class="post-metadata">

### Author: ![Nadya\_Shusharina](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/nadya_shusharina/32/9186_2.png) [@Nadya\_Shusharina](https://discourse.slicer.org/u/Nadya_Shusharina)
#### Post date: [September 13, 2022, 7:06pm UTC](https://discourse.slicer.org/t/installing-slicer-extension-from-script/25241/3 "2022-09-13T19:06:19Z")

</div>

Thank you, it works, I also used parts of your Dockerfile (xfvb-run Slicer).

---

<div class="post-metadata">

### Author: ![Piyush\_Khurana](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/piyush_khurana/32/68815_2.png) [@Piyush\_Khurana](https://discourse.slicer.org/u/Piyush_Khurana)
#### Post date: [December 27, 2023, 4:58pm UTC](https://discourse.slicer.org/t/installing-slicer-extension-from-script/25241/4 "2023-12-27T16:58:49Z")

</div>

Hi Steve,  
Thank you for the script.  
I am trying to find the docs, I wanted to change the extensions path.

I found this: [slicer — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#slicer.app)

But, the docs does not have any slicer.app.extensionsManager

---

<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: [December 27, 2023, 6:14pm UTC](https://discourse.slicer.org/t/installing-slicer-extension-from-script/25241/5 "2023-12-27T18:14:22Z")

</div>

> [@Piyush\_Khurana](#):
>
> But, the docs does not have any slicer.app.extensionsManager

The documentation is not always the best way to learn. Since Slicer is open source, reviewing the code directly using IDE tools or [directly in github](https://github.com/search?q=repo%3ASlicer%2FSlicer%20qSlicerExtensionsManagerModel&type=code) is a good way to learn.

---

<div class="post-metadata">

### Author: ![Piyush\_Khurana](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/piyush_khurana/32/68815_2.png) [@Piyush\_Khurana](https://discourse.slicer.org/u/Piyush_Khurana)
#### Post date: [December 28, 2023, 8:22am UTC](https://discourse.slicer.org/t/installing-slicer-extension-from-script/25241/6 "2023-12-28T08:22:37Z")

</div>

Hmm, thanks for the tip!
