# Execute python scripts without opening 3D-slicer GUI

**URL:** <https://discourse.slicer.org/t/execute-python-scripts-without-opening-3d-slicer-gui/29626>\
**Category:** Development\
**Tags:** segmentation, extensions-manager, python, gui\
**Created:** [May 24, 2023, 10:48am UTC](https://discourse.slicer.org/t/execute-python-scripts-without-opening-3d-slicer-gui/29626 "2023-05-24T10:48:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhanushkannan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dhanushkannan/32/66100_2.png) [@dhanushkannan](https://discourse.slicer.org/u/dhanushkannan)\
**Post date:** [May 24, 2023, 10:48am UTC](https://discourse.slicer.org/t/execute-python-scripts-without-opening-3d-slicer-gui/29626/1 "2023-05-24T10:48:10Z")

</div>

Hi all,  
I have scripted a python code which segments skull from the input DICOM data. When I try to execute the script from CLI using the following command

```auto
Slicer.exe --python-script "app.py" --no-splash --no-main-window

```

the 3d-slicer GUI keeps opening. I need to execute the script without opening GUI.

Thanks in advance. Anyone please help me with it

---

<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 24, 2023, 12:20pm UTC](https://discourse.slicer.org/t/execute-python-scripts-without-opening-3d-slicer-gui/29626/2 "2023-05-24T12:20:10Z")

</div>

Does the full Slicer GUI appear? What Slicer version are you using? Does it do the same if you specify full path for Slicer.exe and app.py?

---

<div class="post-metadata">

**Author:** ![dhanushkannan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dhanushkannan/32/66100_2.png) [@dhanushkannan](https://discourse.slicer.org/u/dhanushkannan)\
**Post date:** [May 24, 2023, 12:40pm UTC](https://discourse.slicer.org/t/execute-python-scripts-without-opening-3d-slicer-gui/29626/3 "2023-05-24T12:40:38Z")

</div>

I have scripted a python code which segments skull from the input DICOM data. When I try to execute the script from CLI using the following command

```auto
Slicer.exe --python-script "app.py" --no-splash --no-main-window

```

the code does not gets executed and the result is not obtained.

If the script is executed using the following command

```auto
Slicer.exe --python-script "app.py"

```

the result is generated but, the GUI appears.

**I need to execute the script without opening GUI.**

---

<div class="post-metadata">

**Author:** ![dhanushkannan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dhanushkannan/32/66100_2.png) [@dhanushkannan](https://discourse.slicer.org/u/dhanushkannan)\
**Post date:** [May 24, 2023, 12:41pm UTC](https://discourse.slicer.org/t/execute-python-scripts-without-opening-3d-slicer-gui/29626/4 "2023-05-24T12:41:22Z")

</div>

yes, the full Slicer GUI appears.  
My Slicer version is 5.2.2

---

<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 24, 2023, 1:18pm UTC](https://discourse.slicer.org/t/execute-python-scripts-without-opening-3d-slicer-gui/29626/5 "2023-05-24T13:18:51Z")

</div>

Everything works perfectly for me with Slicer-5.2.2 on Windows. If I create an `app.py` file with this content:

```python
import slicer
slicer.util.messageBox('test')

```

And run this command:

```
"c:\Users\andra\appdata\Local\NA-MIC\Slicer 5.2.2\Slicer.exe" --no-splash --no-main-window --python-script "c:\Users\andra\appdata\Local\NA-MIC\Slicer 5.2.2\test.py"

```

then all I get is a popup window, displayed by app.py executed by Slicer. The Slicer main window is not displayed.

---

<div class="post-metadata">

**Author:** ![dhanushkannan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dhanushkannan/32/66100_2.png) [@dhanushkannan](https://discourse.slicer.org/u/dhanushkannan)\
**Post date:** [May 25, 2023, 6:04am UTC](https://discourse.slicer.org/t/execute-python-scripts-without-opening-3d-slicer-gui/29626/6 "2023-05-25T06:04:38Z")

</div>

The messageBox appears while executing the code. But the other lines of code are not executed.

I have developed a python script which segments skull from dicom data.

---

<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, 2023, 1:30pm UTC](https://discourse.slicer.org/t/execute-python-scripts-without-opening-3d-slicer-gui/29626/7 "2023-05-26T13:30:57Z")

</div>

I’m not sure what “other lines” you are referring to. If you provide an example script that is not executed the way you expect then we can investigate.

Note that `Slicer.exe` launcher is a GUI application, therefore it cannot print anything to the console. Maybe you think that some code lines are not sure executed because you don’t see the output in the console? See [here](https://slicer.readthedocs.io/en/latest/developer_guide/debugging/tips.html#console-output-on-windows) how you can see the console output on Windows.
