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