# How to use TotalSegmentator from Script with "--no-main-window" option

**URL:** <https://discourse.slicer.org/t/how-to-use-totalsegmentator-from-script-with-no-main-window-option/28144>\
**Category:** Support\
**Created:** [March 2, 2023, 5:03pm UTC](https://discourse.slicer.org/t/how-to-use-totalsegmentator-from-script-with-no-main-window-option/28144 "2023-03-02T17:03:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergio](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sergio](https://discourse.slicer.org/u/Sergio)\
**Post date:** [March 2, 2023, 5:03pm UTC](https://discourse.slicer.org/t/how-to-use-totalsegmentator-from-script-with-no-main-window-option/28144/1 "2023-03-02T17:03:10Z")

</div>

Hi everyone,

I am new 3DSlicer user. I was able to develop my own script which can use TotalSegmentator automatically. But I would like to run it without graphical interface.

The script is working well with graphical interface, but when I use the command “–no-splash --no-main-window”, the program returns me an error because it requires the main-window.

This is the error:

> _Traceback (most recent call last):_
> 
> - File “”, line 5, in \*
> - File “”, line 26, in \*
> - File “/usr/local/apps/3DSlicer/5.2.1/bin/Python/slicer/util.py”, line 1156, in selectModule\*
> - selector = moduleSelector()\*
> - File “/usr/local/apps/3DSlicer/5.2.1/bin/Python/slicer/util.py”, line 1141, in moduleSelector\*
> - raise RuntimeError(“Could not find main window”)\*  
> _RuntimeError: Could not find main window_

Could I have any help with this? It is possible to run the module without the main-window?

Thanks in advance,  
-Sergio

---

<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:** [March 2, 2023, 6:06pm UTC](https://discourse.slicer.org/t/how-to-use-totalsegmentator-from-script-with-no-main-window-option/28144/2 "2023-03-02T18:06:26Z")

</div>

If you want to run headless, you can just use the original tool. [GitHub - wasserth/TotalSegmentator: Tool for robust segmentation of 104 important anatomical structures in CT images](https://github.com/wasserth/TotalSegmentator)

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [March 2, 2023, 6:07pm UTC](https://discourse.slicer.org/t/how-to-use-totalsegmentator-from-script-with-no-main-window-option/28144/3 "2023-03-02T18:07:47Z")

</div>

In that case, you would probably want to install TotalSegmentator in a separate Python instance on your machine [as described here](https://github.com/wasserth/TotalSegmentator#installation) and run your script independently.

But you could also write a script that calls the logic of the TotalSegmentator extension in 3D Slicer which will in turn, perform a TotalSegmentator run.

---

<div class="post-metadata">

**Author:** ![Sergio](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@Sergio](https://discourse.slicer.org/u/Sergio)\
**Post date:** [March 2, 2023, 6:26pm UTC](https://discourse.slicer.org/t/how-to-use-totalsegmentator-from-script-with-no-main-window-option/28144/4 "2023-03-02T18:26:24Z")

</div>

Thank you very much for your quick response.

Yes, I considered also that way. However, I am using the “DicomRtImportExportPlugin” at the end of the segmentation to export the results to DICOM files (Images and RTstructures).

So, what I did is to create an script that is working well when I call it using the following command:

> Slicer --python-script “/full/path/to/myscript.py” --no-splash

But it is not working when I use the next one:

> Slicer --python-script “/full/path/to/myscript.py” --no-splash --no-main-window

Because it seems that TotalSegmentator module requires “main-window”.

Is it possible to run this without main-window?

Thanks,  
-Sergio

---

<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:** [March 2, 2023, 9:49pm UTC](https://discourse.slicer.org/t/how-to-use-totalsegmentator-from-script-with-no-main-window-option/28144/5 "2023-03-02T21:49:39Z")

</div>

This thread should help:

> [@Python script crashes when running w/o GUI due to smoothing effect](https://discourse.slicer.org/t/python-script-crashes-when-running-w-o-gui-due-to-smoothing-effect/28118):
>
> I try to run a python script via the command ./Slicer --no-splash --no-main-window --python-script ‘customScript.py’. It crashes when executing the following line: segmentEditorWidget.setActiveEffectByName("Smoothing"), however, it works when I remove the flag --no-main-window and also when the same code is run via a Jupyter Notebook. Is there any way to apply smoothing effect w/o a GUI? Slicer version: 5.2.2 Thanks!

---

<div class="post-metadata">

**Author:** ![Xiaojie\_Guo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/xiaojie_guo/32/67098_2.png) [@Xiaojie\_Guo](https://discourse.slicer.org/u/Xiaojie_Guo)\
**Post date:** [April 24, 2024, 2:22am UTC](https://discourse.slicer.org/t/how-to-use-totalsegmentator-from-script-with-no-main-window-option/28144/6 "2024-04-24T02:22:10Z")

</div>

Hi, sir, could you give an example of a script that calls the logic of TotalSegmentator extension?

---

<div class="post-metadata">

**Author:** ![Xiaojie\_Guo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/xiaojie_guo/32/67098_2.png) [@Xiaojie\_Guo](https://discourse.slicer.org/u/Xiaojie_Guo)\
**Post date:** [April 24, 2024, 5:44am UTC](https://discourse.slicer.org/t/how-to-use-totalsegmentator-from-script-with-no-main-window-option/28144/7 "2024-04-24T05:44:26Z")

</div>

I know how to do it. I forgot to import it.
