# Installing Slicer Extensions from cmd with python

**URL:** <https://discourse.slicer.org/t/installing-slicer-extensions-from-cmd-with-python/32017>\
**Category:** Support\
**Created:** [October 3, 2023, 8:18pm UTC](https://discourse.slicer.org/t/installing-slicer-extensions-from-cmd-with-python/32017 "2023-10-03T20:18:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![wesselk](https://avatars.discourse-cdn.com/v4/letter/w/ac8455/32.png) [@wesselk](https://discourse.slicer.org/u/wesselk)\
**Post date:** [October 3, 2023, 8:18pm UTC](https://discourse.slicer.org/t/installing-slicer-extensions-from-cmd-with-python/32017/1 "2023-10-03T20:18:22Z")

</div>

Hello, I am working on moving a Slicer routine from my work computer to the machine it will be deployed on. Unfortunately the machine is headless and my employer has a very sensitive firewall preventing extensions from being simply added with slicer.app.installExtensionFromServer().

In the slicer docs [this link](https://gist.github.com/pieper/a9c0ba57de3833c9f5aea68247bda597) is provided for installing from git. I have made the following changes to install from a zipped file instead:

```auto
downloadedArchiveFilePath = "/extensions/SlicerExtension-VMTK-master.zip"

outputDir = os.path.join(slicer.app.temporaryPath, "SlicerVMTK")

try:
    shutil.rmtree(outputDir)
    os.mkdir(outputDir)
except FileNotFoundError:
    pass

slicer.util.extractArchive(
    archiveFilePath=downloadedArchiveFilePath,
    outputDir=outputDir
)

factoryManager = slicer.app.moduleManager().factoryManager()
mod_list = ["ExtractCenterline", "CrossSectionAnalysis"]
for mod in mod_list:
    import os # I know this is odd but somehow it says "os not defined" by the second time through the loop if I omit this
    modulePath = os.path.join(outputDir, "SlicerExtension-VMTK-master", mod, mod+".py")
    factoryManager.registerModule(qt.QFileInfo(modulePath))

factoryManager.loadModules(mod_list)

slicer.util.selectModule("ExtractCenterline")

```

This all runs fine and as a result I am able to run the lines “import ExtractCenterline” and “import CrossSectionAnalysis”. However, when I run the extract centerline logic I am met with the following error:

> line 445, in preprocess  
> import vtkvmtkComputationalGeometryPython as vtkvmtkComputationalGeometry  
> ModuleNotFoundError: No module named ‘vtkvmtkComputationalGeometryPython’

The only other threads I see on this topic encourage downloading the newest stable release, I am using Slicer 5.4.0 and still encountering this issue. I suspect I am not correctly importing the SlicerVMTK extension because I specifically go after the 2 modules I need, but I don’t know how I would get the whole thing as there is no SlicerVMTK.py and I am naively repurposing the example code.

Thanks in advance for any input!

---

<div class="post-metadata">

**Author:** ![wesselk](https://avatars.discourse-cdn.com/v4/letter/w/ac8455/32.png) [@wesselk](https://discourse.slicer.org/u/wesselk)\
**Post date:** [October 25, 2023, 9:20pm UTC](https://discourse.slicer.org/t/installing-slicer-extensions-from-cmd-with-python/32017/2 "2023-10-25T21:20:55Z")

</div>

# Update

I’m now able to run Slicer from command and access _some_ extensions without triggering my employer’s firewall, but it only works for simple extensions like AirwaySegmentation or Sandbox. This method still fails for adding SlicerVMTK: [Documentation here](https://slicer.readthedocs.io/en/latest/user_guide/settings.html#additional-module-paths). It would be nice if someone could point me to the location of the “additional module paths” file so I could just permanently alter it.

What I’d really like to do is to access the “install from file” utility from python/cmd line (which is what I thought em.installExtension() would be but it yells at my file path). But at this point if I knew how I would manually copy the correct directories into the extensions section of Slicer and append the necessary info onto slicer’s extension settings files, etc.

Any advice is appreciated! Thanks

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [October 25, 2023, 11:05pm UTC](https://discourse.slicer.org/t/installing-slicer-extensions-from-cmd-with-python/32017/3 "2023-10-25T23:05:58Z")

</div>

Additional paths are specified in Slicer.ini file under the section:

```auto
[LibraryPaths]
1\path=Extensions-31938/SlicerMorph/lib/Slicer-5.4
10\path=Extensions-31938/MarkupsToModel/lib/Slicer-5.4
11\path=Extensions-31938/MarkupsToModel/lib/Slicer-5.4/qt-loadable-modules
12\path=Extensions-31938/SlicerJupyter/lib/Slicer-5.4
13\path=Extensions-31938/SlicerJupyter/lib/Slicer-5.4/qt-loadable-modules
14\path=Extensions-31938/Sandbox/lib/Slicer-5.4
15\path=Extensions-31938/Sandbox/lib/Slicer-5.4/qt-loadable-modules
16\path=Extensions-31938/SlicerOpenAnatomy/lib/Slicer-5.4
17\path=Extensions-31938/ModelToModelDistance/lib/Slicer-5.4
18\path=Extensions-31938/ModelToModelDistance/lib/Slicer-5.4/cli-modules
19\path=Extensions-31938/LanguagePacks/lib/Slicer-5.4
2\path=Extensions-31938/SegmentEditorExtraEffects/lib/Slicer-5.4
20\path=Extensions-31938/DeveloperToolsForExtensions/lib/Slicer-5.4
21\path=Extensions-31938/MEMOS/lib/Slicer-5.4
22\path=Extensions-31938/PyTorch/lib/Slicer-5.4
3\path=Extensions-31938/SegmentEditorExtraEffects/lib/Slicer-5.4/qt-loadable-modules
4\path=Extensions-31938/SlicerIGT/lib/Slicer-5.4
5\path=Extensions-31938/SlicerIGT/lib/Slicer-5.4/qt-loadable-modules
6\path=Extensions-31938/SlicerIGSIO/lib/Slicer-5.4
7\path=Extensions-31938/SlicerIGSIO/lib/Slicer-5.4/qt-loadable-modules
8\path=Extensions-31938/Pipelines/lib/Slicer-5.4
9\path=Extensions-31938/Pipelines/lib/Slicer-5.4/qt-loadable-modules
size=22

[Modules]
AdditionalPaths=Extensions-31938/SegmentEditorExtraEffects/lib/Slicer-5.4/qt-loadable-modules, Extensions-31938/SegmentEditorExtraEffects/lib/Slicer-5.4/qt-scripted-modules, Extensions-31938/SlicerIGT/lib/Slicer-5.4/qt-loadable-modules, Extensions-31938/SlicerIGT/lib/Slicer-5.4/qt-scripted-modules, Extensions-31938/SlicerIGSIO/lib/Slicer-5.4/qt-loadable-modules, Extensions-31938/Pipelines/lib/Slicer-5.4/qt-scripted-modules, Extensions-31938/MarkupsToModel/lib/Slicer-5.4/qt-loadable-modules, Extensions-31938/SlicerJupyter/lib/Slicer-5.4/qt-loadable-modules, Extensions-31938/SlicerJupyter/lib/Slicer-5.4/qt-scripted-modules, Extensions-31938/SlicerMorph/lib/Slicer-5.4/qt-scripted-modules, Extensions-31938/Sandbox/lib/Slicer-5.4/qt-loadable-modules, Extensions-31938/Sandbox/lib/Slicer-5.4/qt-scripted-modules, Extensions-31938/SlicerOpenAnatomy/lib/Slicer-5.4/qt-scripted-modules, Extensions-31938/ModelToModelDistance/lib/Slicer-5.4/cli-modules, Extensions-31938/LanguagePacks/lib/Slicer-5.4/qt-scripted-modules, Extensions-31938/DeveloperToolsForExtensions/lib/Slicer-5.4/qt-scripted-modules, Extensions-31938/MEMOS/lib/Slicer-5.4/qt-scripted-modules, Extensions-31938/PyTorch/lib/Slicer-5.4/qt-scripted-modules
IgnoreModules=@Invalid()

[PYTHONPATH]
1\path=Extensions-31938/SlicerMorph/lib/Slicer-5.4/qt-scripted-modules
10\path=Extensions-31938/DeveloperToolsForExtensions/lib/Slicer-5.4/qt-scripted-modules
11\path=Extensions-31938/MEMOS/lib/Slicer-5.4/qt-scripted-modules
12\path=Extensions-31938/PyTorch/lib/Slicer-5.4/qt-scripted-modules
2\path=Extensions-31938/SegmentEditorExtraEffects/lib/Slicer-5.4/qt-scripted-modules
3\path=Extensions-31938/SlicerIGT/lib/Slicer-5.4/qt-scripted-modules
4\path=Extensions-31938/Pipelines/lib/Slicer-5.4/qt-scripted-modules
5\path=Extensions-31938/SlicerJupyter/lib/Slicer-5.4/qt-scripted-modules
6\path=Extensions-31938/SlicerJupyter/lib/python3.9/site-packages
7\path=Extensions-31938/Sandbox/lib/Slicer-5.4/qt-scripted-modules
8\path=Extensions-31938/SlicerOpenAnatomy/lib/Slicer-5.4/qt-scripted-modules
9\path=Extensions-31938/LanguagePacks/lib/Slicer-5.4/qt-scripted-modules
size=12

[Paths]
1\path=Extensions-31938/ModelToModelDistance/lib/Slicer-5.4/cli-modules
size=1

```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 25, 2023, 11:59pm UTC](https://discourse.slicer.org/t/installing-slicer-extensions-from-cmd-with-python/32017/4 "2023-10-25T23:59:46Z")

</div>

You can download the extension package from the extension catalog and [install it from file using the Slicer GUI](https://slicer.readthedocs.io/en/latest/user_guide/extensions_manager.html#install-extensions-without-network-connection) or in Python by calling the [installExtension](https://apidocs.slicer.org/master/classqSlicerExtensionsManagerModel.html#a8e723a2a43f1c0e3e8aa74e0ae6bbbef) method of the extensions manager:

```python
slicer.app.extensionsManagerModel().installExtension('/path/to/myextension.zip')

```

---

<div class="post-metadata">

**Author:** ![wesselk](https://avatars.discourse-cdn.com/v4/letter/w/ac8455/32.png) [@wesselk](https://discourse.slicer.org/u/wesselk)\
**Post date:** [October 26, 2023, 5:07pm UTC](https://discourse.slicer.org/t/installing-slicer-extensions-from-cmd-with-python/32017/5 "2023-10-26T17:07:11Z")

</div>

Thanks for that example, I was mistakenly using the GitHub repo .zip 😑

Unfortunately I am still having the same problem as before, simple extensions like Sandbox or AirwaySegmentation are successfully installed like this, but I get the following error when rebooting slicer after installing SlicerVMTK:

> Error(s):  
> Cannot load library /home/qiluser/Slicer/slicer.org/Extensions-31938/SlicerVMTK/lib/Slicer-5.4/qt-loadable-modules/libqSlicerStenosisMeasurement3DModule.so: (libvtkSlicerShapeModuleMRML.so: cannot open shared object file: No such file or directory)  
> libvtkSlicerShapeModuleMRML.so: cannot open shared object file: No such file or directory  
> libvtkSlicerShapeModuleMRML.so: cannot open shared object file: No such file or directory  
> libvtkSlicerShapeModuleMRML.so: cannot open shared object file: No such file or directory  
> Error(s):  
> CLI executable: /home/qiluser/Slicer/slicer.org/Extensions-31938/SlicerVMTK/lib/Slicer-5.4/qt-loadable-modules/vtkvmtk.py  
> The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.  
> Fail to instantiate module “vtkvmtk”  
> The following modules failed to be instantiated:  
> vtkvmtk  
> When loading module “GuidedArterySegmentation” , the dependency “SegmentEditorFloodFilling” failed to be loaded.  
> When loading module “QuickArterySegmentation” , the dependency “SegmentEditorFloodFilling” failed to be loaded.

I am running it like:

> em = slicer.app.extensionsManagerModel()  
> em.interactive = False  
> em.installExtension(extensionFilePath, True) #installing dependencies

My only guess is my work’s firewall is getting back in the way for retrieving the dependencies. Any way those can be manually installed as well?

Thanks so much

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 26, 2023, 5:15pm UTC](https://discourse.slicer.org/t/installing-slicer-extensions-from-cmd-with-python/32017/6 "2023-10-26T17:15:52Z")

</div>

Yes, you need to call `installExtension(..., False)` and manually install all extensions you need (including dependencies).

---

<div class="post-metadata">

**Author:** ![wesselk](https://avatars.discourse-cdn.com/v4/letter/w/ac8455/32.png) [@wesselk](https://discourse.slicer.org/u/wesselk)\
**Post date:** [October 26, 2023, 6:04pm UTC](https://discourse.slicer.org/t/installing-slicer-extensions-from-cmd-with-python/32017/7 "2023-10-26T18:04:56Z")

</div>

Thank you. I am not sure which other dependencies to add at this point. It looks like I have an identical error to [this user](https://discourse.slicer.org/t/vmtk-extension-problem/13699), which you have already identified as a harmless warning.

However, when I run my script which uses ExtractCenterline and CrossSectionAnalysis, centerline extraction works fine but the line “cross\_section\_logic.run()” triggers the following:

> File “/home/qiluser/Slicer/slicer.org/Extensions-31938/SlicerVMTK/lib/Slicer-5.4/qt-scripted-modules/CrossSectionAnalysis.py”, line 871, in run  
> self.updateOutputTable(self.inputCenterlineNode, self.outputTableNode)  
> File “/home/qiluser/Slicer/slicer.org/Extensions-31938/SlicerVMTK/lib/Slicer-5.4/qt-scripted-modules/CrossSectionAnalysis.py”, line 995, in updateOutputTable  
> import vtkSlicerCrossSectionAnalysisModuleLogicPython as vtkSlicerCrossSectionAnalysisModuleLogic  
> ImportError: libvtkSlicerShapeModuleMRML.so: cannot open shared object file: No such file or directory

and I am unable to find anything like ‘SlicerShapeModule’ or related to ‘CrossSectionAnalysis’ as a dependency I could install.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 26, 2023, 6:58pm UTC](https://discourse.slicer.org/t/installing-slicer-extensions-from-cmd-with-python/32017/8 "2023-10-26T18:58:51Z")

</div>

The easiest way to find out all the dependencies (including dependencies of dependencies) is to install the extension on a computer that has network access. If that is not feasible then you get dependencies for an extension from the `depends` field of its extension description file (.s4ext) in the [Extensions Index](https://github.com/Slicer/ExtensionsIndex/).
