Packaging of Slicer resulting in broken SlicerPython

I have manually built Slicer (at e17d2025) 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.

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>
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?

1 Like

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

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…

1 Like

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?

.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).

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.

1 Like

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?

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

1 Like

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

I downloaded the nearly identical Slicer-4.11.0-2019-12-06-win-amd64 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.

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

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

After running ./python-real.exe

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>

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:

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

I started everything from a clean build tree today. There were no build errors and no packaging errors.

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).

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.

2 Likes

Huh. Guess its still the launcher then…

The root cause of the problem is here:

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

Fix committed in r28712.

2 Likes

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

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

2 Likes