# Packaging of Slicer resulting in broken SlicerPython

**URL:** <https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718>\
**Category:** Support\
**Created:** [January 6, 2020, 6:07pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718 "2020-01-06T18:07:11Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [January 6, 2020, 6:07pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/1 "2020-01-06T18:07:11Z")

</div>

I have manually built Slicer (at [e17d2025](https://github.com/Slicer/Slicer/commit/b8402a53083c0f132a37dc72eaa0000b10bc5235)) and when I package the project and install it, then I noticed I’m unable to run SlicerPython.exe/PythonSlicer.exe. It is able to run from my build tree though. I did not have any python paths present in any sys path environment variable at time of build.

```auto
PS C:\Users\JamesButler\AppData\Local\NA-MIC\Slicer 4.11.0-2019-12-06\bin> ./SlicerPython.exe
PS C:\Users\JamesButler\AppData\Local\NA-MIC\Slicer 4.11.0-2019-12-06\bin>

```

```auto
PS C:\S5R\python-install\bin> ./SlicerPython.exe
Python 3.6.7 (default, Jan 6 2020, 07:41:45) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

```

Is there something about LauncherSettings that are messed up in the packaged/installed version?

---

<div class="post-metadata">

**Author:** ![Sam\_Horvath](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sam_horvath/32/3092_2.png) [@Sam\_Horvath](https://discourse.slicer.org/u/Sam_Horvath)\
**Post date:** [January 6, 2020, 6:24pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/2 "2020-01-06T18:24:42Z")

</div>

The PythonSlicer/SlicerPython appears to be working in the most recent nightly.

```auto
PS C:\Users\sam.horvath\AppData\Local\NA-MIC\Slicer 4.11.0-2020-01-05\bin> ./SlicerPython.exe
Python 3.6.7 (default, Jan 5 2020, 23:24:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

```

…testing packaging on local machine currently…

---

<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:** [January 6, 2020, 6:29pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/3 "2020-01-06T18:29:06Z")

</div>

PythonSlicer in latest preview release (Slicer 4.11.0-2020-01-05) install works well for me, too. What do you mean that you are unable to run it? Is it a custom application or a factory build of Slicer?

> [@jamesobutler](#):
>
> Is there something about LauncherSettings that are messed up in the packaged/installed version?

.ini file content is completely different for build and install tree, so it is possible that something only works in one but broken in the other. Most Python launcher settings are taken from the main application’s settings (designated by `additionalSettingsFilePath` field).

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [January 6, 2020, 6:33pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/4 "2020-01-06T18:33:26Z")

</div>

> What do you mean that you are unable to run it?

As I attempted to detail above in the powershell output, it just exits out automatically when I try to run it.

> Is it a custom application or a factory build of Slicer?

It is not a Slicer Custom App. I just cloned, configured Slicer and used the default configure options and built. Then I proceeded to package this Slicer and install.

---

<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:** [January 6, 2020, 6:34pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/5 "2020-01-06T18:34:57Z")

</div>

Does factory-built Slicer installations work? Do you see any difference in the generated .ini files in factory-built and self-built versions in the install tree?

---

<div class="post-metadata">

**Author:** ![Sam\_Horvath](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sam_horvath/32/3092_2.png) [@Sam\_Horvath](https://discourse.slicer.org/u/Sam_Horvath)\
**Post date:** [January 6, 2020, 6:35pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/6 "2020-01-06T18:35:50Z")

</div>

Do you get any output if you run `./SlicerPython.exe --help` ?

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [January 6, 2020, 6:39pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/7 "2020-01-06T18:39:57Z")

</div>

No output either when calling `./SlicerPython.exe --help`

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [January 6, 2020, 6:47pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/8 "2020-01-06T18:47:11Z")

</div>

I downloaded the nearly identical [Slicer-4.11.0-2019-12-06-win-amd64](http://slicer.kitware.com/midas3/api/rest?method=midas.bitstream.download&name=Slicer-4.11.0-2019-12-06-win-amd64.exe&checksum=55a1586c7e72900647c400b94b31071b) generated by the factory machine and running `./SlicerPython.exe` does actually work.

I checked for differences between factory and my package of SlicerPythonLauncherSettings, PythonSlicerLauncherSettings, SlicerDesignerLauncherSettings, and SlicerLauncherSettings. The only difference was in SlicerLauncherSettings where mine specified `revision=e17d202` instead of `revision=28668`.

---

<div class="post-metadata">

**Author:** ![Sam\_Horvath](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sam_horvath/32/3092_2.png) [@Sam\_Horvath](https://discourse.slicer.org/u/Sam_Horvath)\
**Post date:** [January 6, 2020, 6:50pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/9 "2020-01-06T18:50:58Z")

</div>

What happens if you run `./python-real.exe` ?

---

<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:** [January 6, 2020, 6:52pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/10 "2020-01-06T18:52:08Z")

</div>

Does it work if you replace PythonSlicer.exe in your own build/install tree with the one in the factory-built package?

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [January 6, 2020, 6:56pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/11 "2020-01-06T18:56:08Z")

</div>

After running ./python-real.exe

```auto
PS C:\Users\JamesButler\AppData\Local\NA-MIC\Slicer 4.11.0-2019-12-06\bin> ./python-real.exe
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x000025c4 (most recent call first):
PS C:\Users\JamesButler\AppData\Local\NA-MIC\Slicer 4.11.0-2019-12-06\bin>

```

---

<div class="post-metadata">

**Author:** ![Sam\_Horvath](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sam_horvath/32/3092_2.png) [@Sam\_Horvath](https://discourse.slicer.org/u/Sam_Horvath)\
**Post date:** [January 6, 2020, 6:59pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/12 "2020-01-06T18:59:19Z")

</div>

So, this looks like an error with the Python build itself, not the launcher. Things are clearly missing from the install tree .The factory version gives the python prompt for me:

```auto
PS C:\Users\sam.horvath\AppData\Local\NA-MIC\Slicer 4.11.0-2020-01-05\bin> ./python-real.exe
Python 3.6.7 (default, Jan 5 2020, 23:24:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

```

I would try packaging from a clean build

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [January 6, 2020, 7:01pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/13 "2020-01-06T19:01:17Z")

</div>

I started everything from a clean build tree today. There were no build errors and no packaging 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:** [January 6, 2020, 7:01pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/14 "2020-01-06T19:01:35Z")

</div>

> [@Sam\_Horvath](#):
>
> So, this looks like an error with the Python build itself, not the launcher. Things are clearly missing from the install tree .The factory version gives the python prompt for me:

This is very odd. Running ./python-real.exe without the launcher is expected to fail with `No module named 'encodings'` message (since it cannot find very basic Python libraries).

---

<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:** [January 6, 2020, 7:06pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/15 "2020-01-06T19:06:09Z")

</div>

I was able to reproduce the problem on my computer - my builds use `CTKAPPLAUNCHER\bin\CTKAppLauncherW.exe` as `SlicerPython.exe` and `PythonSlicer.exe`. This is incorrect, because `CTKAppLauncherW.exe` is a Windows GUI application and the `CTKAppLauncher.exe` console application should be used as launcher instead.

---

<div class="post-metadata">

**Author:** ![Sam\_Horvath](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sam_horvath/32/3092_2.png) [@Sam\_Horvath](https://discourse.slicer.org/u/Sam_Horvath)\
**Post date:** [January 6, 2020, 7:06pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/16 "2020-01-06T19:06:20Z")

</div>

Huh. Guess its still the launcher then…

---

<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:** [January 6, 2020, 7:12pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/17 "2020-01-06T19:12:46Z")

</div>

The root cause of the problem is here:

> <https://github.com/Slicer/Slicer/blob/fa707a1fd3e78f9ce87969ce6248415ad8392546/CMake/SlicerBlockInstallPython.cmake#L111-L114>

Python should be always configured with CTKAppLauncher executable - regardless of the main application is a console or GUI application. I’ll push a fix.

---

<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:** [January 6, 2020, 7:52pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/18 "2020-01-06T19:52:12Z")

</div>

Fix committed in r28712.

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [January 6, 2020, 11:46pm UTC](https://discourse.slicer.org/t/packaging-of-slicer-resulting-in-broken-slicerpython/9718/19 "2020-01-06T23:46:52Z")

</div>

Thank you @Sam_Horvath for helping with debugging and thank you @lassoan for help debugging and issuing the Slicer fix! 🙏

I’ve tested the fix and can confirm that SlicerPython/PythonSlicer launches correctly when I package and install my Slicer build.
