Installing Slicer Extensions from cmd with python

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 is provided for installing from git. I have made the following changes to install from a zipped file instead:

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!

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

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

[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


1 Like

You can download the extension package from the extension catalog and install it from file using the Slicer GUI or in Python by calling the installExtension method of the extensions manager:

slicer.app.extensionsManagerModel().installExtension('/path/to/myextension.zip')
1 Like

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

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

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

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

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.

1 Like