# Running Slicer without GUI?

**URL:** <https://discourse.slicer.org/t/running-slicer-without-gui/11720>\
**Category:** Support\
**Created:** [May 26, 2020, 5:36pm UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720 "2020-05-26T17:36:26Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![lennymartinez](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lennymartinez/32/6918_2.png) [@lennymartinez](https://discourse.slicer.org/u/lennymartinez)\
**Post date:** [May 26, 2020, 5:36pm UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/1 "2020-05-26T17:36:26Z")

</div>

I’ve installed Slicer on an Ubuntu cloud instance (AWS/GCP) and I want to run it with a self-made extension and no GUI… Is there documentation on the slicer site that I’m missing to be able to do this? I’ve found info about using Python to do things, but I want to essentially go: Slicer, do this task, using this folder, and put the output in this location.

---

<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:** [May 26, 2020, 7:08pm UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/2 "2020-05-26T19:08:32Z")

</div>

Is docker an option for you? [Here’s an example](https://github.com/pieper/SlicerDockers#running-a-slicer-analysis-script-in-an-instance) of a command line tool based on Slicer and [this is another one](https://github.com/QIICR/dcmheat/blob/master/docker/SlicerConvert.py). If you don’t use docker you would need a different way of having a desktop to access all of Slicer. If you don’t need graphics you might be able to get by with PythonSlicer and access just logic classes.

Maybe you can describe your processing task in more detail if you need more explicit suggestions.

---

<div class="post-metadata">

**Author:** ![lennymartinez](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lennymartinez/32/6918_2.png) [@lennymartinez](https://discourse.slicer.org/u/lennymartinez)\
**Post date:** [May 26, 2020, 7:19pm UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/3 "2020-05-26T19:19:17Z")

</div>

I have dicom images I want to turn into OBJ models using an extension that’s already made. My idea was to use a form to upload the images to AWS/GCP and there have Slicer take them as input with the extension and then output the obj. The extension segments the file to create a 3D render.

I’ve never worked with docker, but I can check it out as well as PythonSlicer.

---

<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:** [May 26, 2020, 7:41pm UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/4 "2020-05-26T19:41:36Z")

</div>

If you don’t want to learn Javascript to create a frontend, then it is also an option to create a web application using Slicer Jupyter notebook and [Voila](https://voila.readthedocs.io/en/stable/using.html).

You can use standard IPython widgets for file upload/download/display. Voila takes care of selectively locking down the notebook, so users can still interact with widgets but they will not see or able to modify code in the notebook.

See a number of example web applications here:

[https://voila-gallery.org/](https://voila-gallery.org/)

They are all hosted on the free binder service and a new container is created for each user from scratch, so initial loading of the page may take a minute, but of if you set up your own server then page loading should be instantaneous.

---

<div class="post-metadata">

**Author:** ![Davide\_Cester](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/davide_cester/32/6564_2.png) [@Davide\_Cester](https://discourse.slicer.org/u/Davide_Cester)\
**Post date:** [May 29, 2020, 7:54pm UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/5 "2020-05-29T19:54:03Z")

</div>

> [@lennymartinez](#):
>
> I want to essentially go: Slicer, do this task, using this folder, and put the output in this location

From my recent experience on headless Slicer on Ubuntu, I think something like the following on the command line could be one way to go:

```
xvfb-run -a /slicer_path/Slicer --no-splash --python-script mycode.py

```

here “xvfb” is a package you need to install on your Ubuntu instance. Running “xvfb-run program” will start “program” with a dummy graphical interface, otherwise it complains that it can’t connect to X server.

If it works for you, you can put everything you want in mycode.py.

---

<div class="post-metadata">

**Author:** ![Jeff\_Pennal](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jeff_pennal/32/8400_2.png) [@Jeff\_Pennal](https://discourse.slicer.org/u/Jeff_Pennal)\
**Post date:** [October 9, 2020, 7:39pm UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/6 "2020-10-09T19:39:25Z")

</div>

Hi Lenny, this isn’t directly related to your question, but I am working on a similar project (DICOM -\> OBJ). Is the extension that you are using something that is custom to your project or an open source extension. If its open source, would you mind sharing a link to it?

Thanks,  
Jeff

---

<div class="post-metadata">

**Author:** ![kpopuri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/kpopuri/32/6263_2.png) [@kpopuri](https://discourse.slicer.org/u/kpopuri)\
**Post date:** [October 29, 2020, 8:50pm UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/7 "2020-10-29T20:50:53Z")

</div>

thanks! it works like magic

---

<div class="post-metadata">

**Author:** ![fpsiddiqui91](https://avatars.discourse-cdn.com/v4/letter/f/53a042/32.png) [@fpsiddiqui91](https://discourse.slicer.org/u/fpsiddiqui91)\
**Post date:** [March 24, 2021, 9:20am UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/8 "2021-03-24T09:20:50Z")

</div>

Hi, I have been working on developing a web app as suggested by @lassoan following this link:

> [@Run Slicer in your web browser - as a Jupyter notebook or as a full application](https://discourse.slicer.org/t/run-slicer-in-your-web-browser-as-a-jupyter-notebook-or-as-a-full-application/11569):
>
> It has been possible to use Slicer from Jupyter notebooks but the most recent Slicer Preview Release takes this to a whole new level. [Click here to try a few example interactive notebooks now](https://mybinder.org/v2/gh/slicer/SlicerNotebooks/master) - or see a short video demonstrating the new features: [[Medical image processing in your web browser using Jupyter notebooks and 3D Slicer] ](https://www.youtube.com/watch?v=oZ3_cRXX2QM) Highlights: Improved interactive use You can now use IPython widgets (sliders, buttons, etc.) to control Slicer or adjust processing and visualization…

. I successfully created a Slicer Jupyter notebook. However, on integrating with Voila I have some issues.

The application fails to launch, even after several tries.

This happens as soon as I add “docker” and “start” file in my repository.

Am I missing some thing? Can you provide any example repository which works with slicer jupyter notebook and voila.

For your reference, my repository link is:

> **[GitHub - FaizanSiddiqui91/Slicer\_binder](https://github.com/FaizanSiddiqui91/Slicer_binder)**
>
> Contribute to FaizanSiddiqui91/Slicer\_binder development by creating an account on GitHub.

---

<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:** [March 24, 2021, 3:50pm UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/9 "2021-03-24T15:50:11Z")

</div>

Does everything work well (Slicer kernel starts without problems) if you don’t use Voila?

---

<div class="post-metadata">

**Author:** ![fpsiddiqui91](https://avatars.discourse-cdn.com/v4/letter/f/53a042/32.png) [@fpsiddiqui91](https://discourse.slicer.org/u/fpsiddiqui91)\
**Post date:** [March 24, 2021, 3:52pm UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/10 "2021-03-24T15:52:21Z")

</div>

Thank you for your reply @lassoan. Yes, slicer works well. I just need to integrate it with Viola. I think I am missing something in the Docker file.  
I have tried slicer in my other repository. It works well. I am following your repository. Just the integration with viola is a bit difficult.

---

<div class="post-metadata">

**Author:** ![fpsiddiqui91](https://avatars.discourse-cdn.com/v4/letter/f/53a042/32.png) [@fpsiddiqui91](https://discourse.slicer.org/u/fpsiddiqui91)\
**Post date:** [March 24, 2021, 9:31pm UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/12 "2021-03-24T21:31:22Z")

</div>

hi @lassoan . This is the example I have been following to generate my own repository and notebook. It works fine. The problem arises only when I try to run the app through Voila.

> **[Slicer/SlicerNotebooks](https://github.com/slicer/SlicerNotebooks/tree/7e61957c0b9ee180c49b9f2e86eec738b037dd82)**
>
> 7e61957c0b9ee180c49b9f2e86eec738b037dd82

Can you help me with this?  
Thanks alot

---

<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:** [April 9, 2021, 1:23am UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/13 "2021-04-09T01:23:28Z")

</div>

For reference, this has been discussed at the weekly developer meeting: [2021.04.06 Hangout - #3 by jcfr](https://discourse.slicer.org/t/2021-04-06-hangout/16953/3)

---

<div class="post-metadata">

**Author:** ![jakehockman](https://avatars.discourse-cdn.com/v4/letter/j/47e85d/32.png) [@jakehockman](https://discourse.slicer.org/u/jakehockman)\
**Post date:** [November 7, 2021, 4:34pm UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/14 "2021-11-07T16:34:05Z")

</div>

I had trouble importing DICOM files using xvfb. I kept receiving database not open/filenotfound errors when using the DICOMUtils.TemporaryDICOMDatabase(). I was running ubuntu 21 on GCS. In case anyone else has this issue, manually setting the database solved the issue.

```auto
dicomDataDir = 'path/to/dicoms'
dbDir = 'path/to/database'

db = ctk.ctkDICOMDatabase()
db.openDatabase(dbDir)
slicer.dicomDatabase = db

import DICOMLib
DICOMLib.importDicom(dicomDataDir)
dicomFiles = slicer.util.getFilesInDirectory(dicomDataDir)
loadablesByPlugin, loadEnabled = DICOMLib.getLoadablesFromFileLists([dicomFiles])
loadedNodeIDs = DICOMLib.loadLoadables(loadablesByPlugin)

```

---

<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:** [November 7, 2021, 5:13pm UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/15 "2021-11-07T17:13:12Z")

</div>

Could you please copy here the command that launches Slicer and the full console output?

---

<div class="post-metadata">

**Author:** ![jakehockman](https://avatars.discourse-cdn.com/v4/letter/j/47e85d/32.png) [@jakehockman](https://discourse.slicer.org/u/jakehockman)\
**Post date:** [November 7, 2021, 6:11pm UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/16 "2021-11-07T18:11:44Z")

</div>

Yes here they are. I tried the method in the script repository and also a second attempt from here:[Fastest way to load DICOM - #2 by lassoan](https://discourse.slicer.org/t/fastest-way-to-load-dicom/9317/2)

**slicer\_load\_scans\_debug.py**

```auto
dicomDataDir = 'path/to/dicoms'

loadedNodeIDs = []

from DICOMLib import DICOMUtils

with DICOMUtils.TemporaryDICOMDatabase() as db:
	DICOMUtils.importDicom(dicomDataDir, db)
	patientUIDs = db.patients()
	for patientUID in patientUIDs:
		loadedNodeIDs.extend(DICOMUtils.loadPatientByUID(patientUID))

```

**Command**

```auto
xvfb-run -a Slicer-4.11.20210226-linux-amd64/Slicer --no-splash --no-main-window --python-script 'startup/slicer_load_scans_debug.py'

```

**Output:**

```auto

qSlicerSequencesModulePrivate::addToolBar: no main window is available, toolbar is not added
Switching to temporary DICOM database: /tmp/Slicer-neureal2020/20211107_173523_TempDICOMDatabase
TagCacheDatabase adding table
Patient ID is empty, using studyInstanceUID (#########) as patient ID # repeats x169
"DICOM indexer has successfully inserted 169 files [0.14s]"
"DICOM indexer has successfully processed 169 files [0.18s]"
Patient ID is empty, using studyInstanceUID (#########) as patient ID #repeats x169
"DICOM indexer has updated display fields for 169 files [0.07s]"
Loading with imageIOName: GDCM
vtkITKArchetypeImageSeriesReader::ExecuteInformation: Archetype file /tmp/Slicer-user/scan_name_TempDICOMDatabase/path/to/dicoms/FILE12 does not exist.
Algorithm vtkITKArchetypeImageSeriesScalarReader(0x5826580) returned failure for request: vtkInformation (0x58278e0)
  Debug: Off
  Modified Time: 128579
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_INFORMATION
  ALGORITHM_AFTER_FORWARD: 1
  FORWARD_DIRECTION: 0
Could not read scalar volume using GDCM approach. Error is: FileNotFoundError
Loading with imageIOName: DCMTK
vtkITKArchetypeImageSeriesReader::ExecuteInformation: Archetype file Archetype file /tmp/Slicer-user/scan_name_TempDICOMDatabase/path/to/dicoms/FILE12 does not exist.
Algorithm vtkITKArchetypeImageSeriesScalarReader(0x38bdd60) returned failure for request: vtkInformation (0x5a45430)
  Debug: Off
  Modified Time: 128662
  Reference Count: 1
  Registered Events: (none)
  Request: REQUEST_INFORMATION
  ALGORITHM_AFTER_FORWARD: 1
  FORWARD_DIRECTION: 0
Could not read scalar volume using DCMTK approach. Error is: FileNotFoundError

```

This was the second attempt:

**slicer\_load\_scans\_debug.py**

```auto
import DICOMLib
import re
DICOMLib.importDicom(dicomDataDir)
dicomFiles = slicer.util.getFilesInDirectory(dicomDataDir)
loadablesByPlugin, loadEnabled = DICOMLib.getLoadablesFromFileLists([dicomFiles])
loadedNodeIDs = DICOMLib.loadLoadables(loadablesByPlugin)
for loadedNodeID in loadedNodeIDs:
    node = slicer.mrmlScene.GetNodeByID(loadedNodeID)
    safeFileName = re.sub(r'(?u)[^-\w.]', '', node.GetName().strip().replace(' ', '_'))
    slicer.util.saveNode(node, '{0}/{1}.nrrd'.format(outputDir, safeFileName))

```

**Output**

```auto
qSlicerSequencesModulePrivate::addToolBar: no main window is available, toolbar is not added
Patient ID is empty, using studyInstanceUID (#########) as patient ID # repeats x169
"DICOM indexer has successfully inserted 169 files [0.14s]"
"DICOM indexer has successfully processed 169 files [0.18s]"
Patient ID is empty, using studyInstanceUID (#########) as patient ID #repeats x169
"DICOM indexer has updated display fields for 169 files [0.07s]"
Loading with imageIOName: GDCM
Could not load "/tmp/Slicer-user/scan_name_TempDICOMDatabase/path/to/dicoms/FILE12" 
DCMTK says: No such file or directory
File /tmp/Slicer-user/scan_name_TempDICOMDatabase/path/to/dicoms/FILE12 could not be initialized.
No geometry information available for DICOM data, skipping corner calculations

```

It goes on to give me errors related to saving the .nrrd. I could not reproduce the database not found error, apologies.

---

<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:** [November 7, 2021, 6:16pm UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/17 "2021-11-07T18:16:26Z")

</div>

Please try with the latest Slicer Preview Release.

If it fails exactly the same way then check if there referred `/tmp/Slicer-user/scan_name_TempDICOMDatabase/path/to/dicoms/FILE12` file exists or not.

---

<div class="post-metadata">

**Author:** ![jakehockman](https://avatars.discourse-cdn.com/v4/letter/j/47e85d/32.png) [@jakehockman](https://discourse.slicer.org/u/jakehockman)\
**Post date:** [November 7, 2021, 8:17pm UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/18 "2021-11-07T20:17:47Z")

</div>

Thanks for your reply. I retried on the latest Preview Release and I got the same error with an additional line saying “Failed to find patient…”:

```auto
"DICOM indexer has successfully processed 169 files [0.18s]"
Patient ID is empty, using studyInstanceUID (#########) as patient ID #repeats x169
Failed to find patient with PatientsName= and PatientID=

```

I made copies of the DICOM files and added PatientID and PatientName metadata. I reran and got the same error without that extra line, so it must be unrelated.

With regards to your second comment, I used the following code and the file does not exist.

```auto
with DICOMUtils.TemporaryDICOMDatabase() as db:
	DICOMUtils.importDicom(dicomDataDir, db)
	os.system('ls {}'.format(db.databaseDirectory))

Output:
ctkDICOM.sql
ctkDICOMTagCache.sql

```

Also just to be clear, I ran the same **slicer\_load\_scans\_debug.py** with a GUI on my laptop and it loaded the scans without errors.

---

<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:** [November 7, 2021, 11:08pm UTC](https://discourse.slicer.org/t/running-slicer-without-gui/11720/19 "2021-11-07T23:08:54Z")

</div>

Your first example did not contain the node saving part. The second example used the Slicer DICOM database. So, I created a new script (based on the example in the Slicer script repository + adding your node saving) and it worked well for me:

```python
dicomDataDir = r"c:\tmp\eclipse-8.1.20-phantom-ent-ctonly"
outputDir = r"c:\tmp\output"

from DICOMLib import DICOMUtils
import re

try:
    loadedNodeIDs = [] # this list will contain the list of all loaded node IDs
    from DICOMLib import DICOMUtils
    with DICOMUtils.TemporaryDICOMDatabase() as db:
        DICOMUtils.importDicom(dicomDataDir, db)
        patientUIDs = db.patients()
        for patientUID in patientUIDs:
            loadedNodeIDs.extend(DICOMUtils.loadPatientByUID(patientUID))

    for loadedNodeID in loadedNodeIDs:
        node = slicer.mrmlScene.GetNodeByID(loadedNodeID)
        safeFileName = re.sub(r'(?u)[^-\w.]', '', node.GetName().strip().replace(' ', '_'))
        print(f"Saving {safeFileName}...")
        slicer.util.saveNode(node, '{0}/{1}.nrrd'.format(outputDir, safeFileName))

finally:
    exit()

```

I’ve executed by this command (powershell and tee are used to redirect the output so that I can see it, but should not be needed on linux/macOS):

```auto
powershell ".\Slicer.exe --no-splash --no-main-window --python-script 'c:\Users\andra\AppData\Local\NA-MIC\Slicer 4.13.0-2021-11-03\slicer_load_scans_debug.py' 2>&1 | tee out.txt"

```

I saw that you used relative paths - I’m not sure what they should be resolved to, so I used absolute paths everywhere. You may try to do that, too.
