Installing Slicer extension from script

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:

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, 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

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

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

1 Like

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

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 is a good way to learn.

Hmm, thanks for the tip!