# Slicer --no-main-window --python-script in windows command prompt not working

**URL:** https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481
**Category:** Development
**Created:** [April 12, 2019, 3:16pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481 "2019-04-12T15:16:21Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Allison\_Clement](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/allison_clement/32/3249_2.png) [@Allison\_Clement](https://discourse.slicer.org/u/Allison_Clement)
#### Post date: [April 12, 2019, 3:16pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/1 "2019-04-12T15:16:21Z")

</div>

I am trying to submit a python code to slicer python interactor via the windows command line. I can run my slicer using --python-script mypath. When I add --no-main-window before the --python-script mypath, the code does not run.

Thanks!  
AC

---

<div class="post-metadata">

### Author: ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)
#### Post date: [April 12, 2019, 11:44pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/2 "2019-04-12T23:44:57Z")

</div>

Maybe it helps if you look at an example for a script that does run without main window:

> **[SlicerRT/BatchProcessing at master · SlicerRt/SlicerRT](https://github.com/SlicerRt/SlicerRT/tree/master/BatchProcessing)**
>
> master/BatchProcessing

---

<div class="post-metadata">

### Author: ![Allison\_Clement](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/allison_clement/32/3249_2.png) [@Allison\_Clement](https://discourse.slicer.org/u/Allison_Clement)
#### Post date: [April 15, 2019, 3:24pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/4 "2019-04-15T15:24:14Z")

</div>

My .py file runs when using --python-script, without --no-main-window prior.

---

<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 15, 2019, 3:34pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/5 "2019-04-15T15:34:33Z")

</div>

> [@Allison\_Clement](#):
>
> does not run

Is any error displayed? Is any error logged in the application log? Which Slicer version do you use?

---

<div class="post-metadata">

### Author: ![Allison\_Clement](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/allison_clement/32/3249_2.png) [@Allison\_Clement](https://discourse.slicer.org/u/Allison_Clement)
#### Post date: [April 15, 2019, 8:21pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/6 "2019-04-15T20:21:48Z")

</div>

Currently using Slicer 4.8.1 , there is no error it seems to be running in the background when I look at the task manager however the that I request to save in the python code are not being saved.

---

<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 15, 2019, 8:41pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/7 "2019-04-15T20:41:46Z")

</div>

Let us know if the problem persists with latest stable version (4.10.1).

---

<div class="post-metadata">

### Author: ![tbillah](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tbillah/32/4139_2.png) [@tbillah](https://discourse.slicer.org/u/tbillah)
#### Post date: [April 16, 2020, 4:53pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/8 "2020-04-16T16:53:45Z")

</div>

Hi @lassoan, same problem on Win10 PowerShell, Slicer-4.10.2:

> .\Slicer.exe --help  
> .\Slicer.exe --launch python-real

Nothing happens, no errors are displayed either.

---

<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 16, 2020, 6:03pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/9 "2020-04-16T18:03:44Z")

</div>

It works as intended but I can see how this may be confusing.

In official Slicer releases on Windows, Slicer.exe is not a console application, so you just don’t see the output. It is still there, for example run this instead (`more` is a console application, so it can display text):

```
.\Slicer.exe --help | more

```

For Python, we included a launcher that is built as a console application. Use that for running Python interactively:

```
.\SlicerPython.exe
```

---

<div class="post-metadata">

### Author: ![tbillah](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tbillah/32/4139_2.png) [@tbillah](https://discourse.slicer.org/u/tbillah)
#### Post date: [April 16, 2020, 7:02pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/10 "2020-04-16T19:02:35Z")

</div>

@lassoan, I am aware of `SlicerPython.exe `. But that won’t have knowledge of additional settings like `Slicer.exe --launch python-real` has.

See my use case below:

> C:\Users\tashr\Downloads\“Slicer 4.10.2”\Slicer.exe --launch python-real .\Test\run\_test.py

The above command is the Windows variant of a Linux command minus the `.exe`, that I would like to run on PowerShell. Let me know if there is a way of doing that.

By the way, I followed your `| more` idea and the following works fine:

> C:\Users\tashr\Downloads\“Slicer 4.10.2”\Slicer.exe --launch python-real .\Test\run\_test.py | more

---

<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 16, 2020, 7:22pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/11 "2020-04-16T19:22:33Z")

</div>

PythonSlicer.exe inherits all launcher settings from Slicer.exe (as you can see it from `additionalSettingsFilePath=<APPLAUNCHER_SETTINGS_DIR>/SlicerLauncherSettings.ini` line in `PythonSlicerLauncherSettings.ini`), and it runs `python-real.exe`. Therefore, `Slicer.exe --launch python-real.exe ...args...` does exactly the same as `PythonSlicer.exe ...args...`, the only difference is that one is a console application, while the other is not.

By the way, you can capture output of `Slicer.exe` by redirecting it to an output file:

```
Slicer.exe --help >output.txt
```

---

<div class="post-metadata">

### Author: ![tbillah](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tbillah/32/4139_2.png) [@tbillah](https://discourse.slicer.org/u/tbillah)
#### Post date: [April 16, 2020, 7:33pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/12 "2020-04-16T19:33:29Z")

</div>

Sorry, I should have mentioned, `SlicerPython.exe .\Test\run_test.py` did not find one of the SlicerDMRI modules I installed.

I do confirm that the module is found by:

- Slicer GUI
- `C:\Users\tashr\Downloads\“Slicer 4.10.2”\Slicer.exe --launch python-real .\Test\run_test.py | more`

which is why I am convinced that `SlicerPython.exe` doesn’t find them.

---

<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 16, 2020, 7:57pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/13 "2020-04-16T19:57:45Z")

</div>

SlicerApp-real.exe loads more libraries than python-real.exe, but there should be no difference between if you start python-real.exe when you use Slicer.exe/PythonSlicer.exe launchers.

Can you post the exact Python command that succeeds when executed using `Slicer.exe --launch python-real` but not when launched using `PythonSlicer.exe`?

---

<div class="post-metadata">

### Author: ![tbillah](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tbillah/32/4139_2.png) [@tbillah](https://discourse.slicer.org/u/tbillah)
#### Post date: [April 16, 2020, 8:11pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/14 "2020-04-16T20:11:16Z")

</div>

Does not succeed:

> C:\Users\tashr\Downloads"Slicer 4.10.2"\bin\SlicerPython.exe .\Test\run\_test.py

succeeds:

> C:\Users\tashr\Downloads"Slicer 4.10.2"\Slicer.exe --launch python-real .\Test\run\_test.py | more

Here, I am measuring success in terms of the exec’s ability to find ExtensionModules I installed.

Here is the [Test/run\_test.py](https://github.com/pnlbwh/SlicerDiffusionQC/blob/master/Test/run_test.py) script anyway and [this](https://github.com/pnlbwh/SlicerDiffusionQC/blob/master/diffusionqclib/diffusionqclib/gradient_process.py#L36) is the line that fails:

> masking\_cli = distutils.spawn.find\_executable(“DiffusionWeightedVolumeMasking”)

---

<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 16, 2020, 8:21pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/15 "2020-04-16T20:21:01Z")

</div>

When trying to execute:

```
masking_cli = distutils.spawn.find_executable("DiffusionWeightedVolumeMasking")

```

I get this error:

```
AttributeError: module 'distutils' has no attribute 'spawn'

```

Probably Python2/3 issue. Slicer-4.10 will be retired very soon, so I would not spend time with issues that are only reproducible there. Can you provide an example for latest Slicer-4.11?

---

<div class="post-metadata">

### Author: ![tbillah](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tbillah/32/4139_2.png) [@tbillah](https://discourse.slicer.org/u/tbillah)
#### Post date: [April 16, 2020, 8:30pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/16 "2020-04-16T20:30:18Z")

</div>

Sorry, I have Slicer-4.10 only.

```python
distutils. __version__'2.7.13'

```

---

<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 16, 2020, 8:32pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/17 "2020-04-16T20:32:05Z")

</div>

I can only help with issues that I can reproduce in Slicer-4.11. You can install Slicer-4.11 from [download.slicer.org](http://download.slicer.org). If you are still based on Slicer-4.10 then it may be a good time to start transitioning to Slicer-4.11.

---

<div class="post-metadata">

### Author: ![tbillah](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tbillah/32/4139_2.png) [@tbillah](https://discourse.slicer.org/u/tbillah)
#### Post date: [April 16, 2020, 8:59pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/19 "2020-04-16T20:59:02Z")

</div>

@lassoan, can you try this?

```python
import distutils.spawn
masking_cli = distutils.spawn.find_executable("DiffusionWeightedVolumeMasking")

```

---

<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 16, 2020, 9:27pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/20 "2020-04-16T21:27:13Z")

</div>

There is indeed a difference between these (one finds the application, while the other does not):

```
Slicer.exe --launch python-real.exe -c "import distutils.spawn; print(distutils.spawn.find_executable('DiffusionWeightedVolumeMasking'))" 2>&1 | more

PythonSlicer.exe -c "import distutils.spawn; print(distutils.spawn.find_executable('DiffusionWeightedVolumeMasking'))" 2>&1 | more

```

@jcfr Why Slicer.exe adds extensions to PATH env variable, while PythonSlicer does not?

```
Slicer.exe --launch python-real.exe -c "import os; print(os.environ['PYTHONPATH'])" 2>&1 | more

PythonSlicer.exe -c "import os; print(os.environ['PYTHONPATH'])" 2>&1 | more
```

---

<div class="post-metadata">

### Author: ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)
#### Post date: [April 16, 2020, 9:57pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/21 "2020-04-16T21:57:23Z")

</div>

> [@lassoan](#):
>
> Why Slicer.exe adds extensions to PATH env variable, while PythonSlicer does not?

Because it was not designed to do so. It is currently a wrapper around the standard python interpreter.

To illustrate, here are the associated launcher settings:

> **PythonSlicerLauncherSettings.ini**
>
> ```auto
> [General]
> launcherNoSplashScreen=true
> launcherSplashImagePath=
> launcherSplashScreenHideDelayMs=
> additionalLauncherHelpShortArgument=
> additionalLauncherHelpLongArgument=
> additionalLauncherNoSplashArguments=
> 
> additionalSettingsFilePath=/home/jcfr/Projects/Slicer-Release/Slicer-build/SlicerLauncherSettings.ini
> additionalSettingsExcludeGroups=General,Application,ExtraApplicationToLaunch
> 
> [Application]
> path=<APPLAUNCHER_DIR>/./python
> arguments=
> name=PythonSlicer
> revision=
> organizationDomain=
> organizationName=
> 
> [ExtraApplicationToLaunch]
> 
> [Environment]
> additionalPathVariables=PYTHONPATH
> 
> [LibraryPaths]
> 1\path=/home/jcfr/Projects/Slicer-Release/python-install/lib
> 2\path=/home/jcfr/Projects/Slicer-Release/OpenSSL
> size=2
> 
> [Paths]
> 1\path=<APPLAUNCHER_DIR>
> size=1
> 
> [EnvironmentVariables]
> PYTHONHOME=/home/jcfr/Projects/Slicer-Release/python-install
> PYTHONNOUSERSITE=1
> PIP_REQUIRE_VIRTUALENV=0
> SSL_CERT_FILE=<APPLAUNCHER_DIR>/../../Slicer-build/share/Slicer-4.11/Slicer.crt
> 
> [PYTHONPATH]
> 1\path=/home/jcfr/Projects/Slicer-Release/python-install/lib/python3.6
> 2\path=/home/jcfr/Projects/Slicer-Release/python-install/lib/python3.6/lib-dynload
> 3\path=/home/jcfr/Projects/Slicer-Release/python-install/lib/python3.6/site-packages
> size=3
> 
> ```

> **PythonSlicerLauncherSettingsToInstall.ini**
>
> ```auto
> [General]
> launcherNoSplashScreen=true
> launcherSplashImagePath=
> launcherSplashScreenHideDelayMs=
> additionalLauncherHelpShortArgument=
> additionalLauncherHelpLongArgument=
> additionalLauncherNoSplashArguments=
> 
> additionalSettingsFilePath=<APPLAUNCHER_SETTINGS_DIR>/SlicerLauncherSettings.ini
> additionalSettingsExcludeGroups=General,Application,ExtraApplicationToLaunch
> 
> [Application]
> path=<APPLAUNCHER_DIR>/./python-real
> arguments=
> name=PythonSlicer
> revision=
> organizationDomain=
> organizationName=
> 
> [ExtraApplicationToLaunch]
> 
> [Environment]
> additionalPathVariables=PYTHONPATH
> 
> [LibraryPaths]
> 1\path=<APPLAUNCHER_DIR>/../bin
> 2\path=<APPLAUNCHER_DIR>/../lib/Slicer-4.11
> 3\path=<APPLAUNCHER_DIR>/../lib/Python/lib
> size=3
> 
> [Paths]
> 1\path=<APPLAUNCHER_DIR>
> size=1
> 
> [EnvironmentVariables]
> PYTHONHOME=<APPLAUNCHER_DIR>/../lib/Python
> PYTHONNOUSERSITE=1
> PIP_REQUIRE_VIRTUALENV=0
> SSL_CERT_FILE=<APPLAUNCHER_DIR>/../share/Slicer-4.11/Slicer.crt
> 
> [PYTHONPATH]
> 1\path=<APPLAUNCHER_DIR>/../lib/Python/lib/Python/lib/python3.6
> 2\path=<APPLAUNCHER_DIR>/../lib/Python/lib/Python/lib/python3.6/lib-dynload
> 3\path=<APPLAUNCHER_DIR>/../lib/Python/lib/Python/lib/python3.6/site-packages
> 4\path=<APPLAUNCHER_DIR>/../bin/Python
> size=4
> 
> ```

---

<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 16, 2020, 11:12pm UTC](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481/23 "2020-04-16T23:12:55Z")

</div>

It does not help if I add `--launcher-additional-settings "c:/Users/andra/AppData/Local/NA-MIC/Slicer 4.11.0-2020-04-12/bin/SlicerLauncherSettings.ini"`, which is not surprising since `SlicerPythonLauncherSettings.ini` already includes it, see:

```
additionalSettingsFilePath=<APPLAUNCHER_SETTINGS_DIR>/SlicerLauncherSettings.ini
additionalSettingsExcludeGroups=General,Application,ExtraApplicationToLaunch

```

Where do extension paths (such as `C:/Users/andra/AppData/Roaming/NA-MIC/Extensions-28946/DiffusionQC/Lib/site-packages`) get added to PYTHONPATH?

[Next page](https://discourse.slicer.org/t/slicer-no-main-window-python-script-in-windows-command-prompt-not-working/6481.md?page=2)
