How to select python interpreter in Slicer on VSCode?

Hello, I failed to select python interpreter in Slicer on VSCode. The system is MacOS 13.4. I also tried other IDE but no success. However, I can run python script by python interpreter in Slicer from Terminal.

Here is the error information:

[error] [Error: Command failed: /Applications/Slicer.app/Contents/bin/PythonSlicer -I /Users/admin/.vscode/extensions/ms-python.python-2023.8.0/pythonFiles/get_output_via_markers.py /Users/admin/.vscode/extensions/ms-python.python-2023.8.0/pythonFiles/interpreterInfo.py
error: Application is NOT executable [/Applications/Slicer.app/Contents/bin/./python-real]
Usage
  PythonSlicer [options]

Options
  --launcher-help                                 Display help
  --launcher-version                              Show launcher version information
  --launcher-verbose                              Verbose mode
  --launch                                        Specify the application to launch
  --launcher-detach                               Launcher will NOT wait for the application to finish
  --launcher-no-splash                            Hide launcher splash
  --launcher-timeout                              Specify the time in second before the launcher kills the application. -1 means no timeout (default: -1)
  --launcher-load-environment                     Specify the saved environment to load.
  --launcher-dump-environment                     Launcher will print environment variables to be set, then exit
  --launcher-show-set-environment-commands        Launcher will print commands suitable for setting the parent environment (i.e. using 'eval' in a POSIX shell), then exit
  --launcher-additional-settings                  Additional settings file to consider
  --launcher-additional-settings-exclude-groups   Comma separated list of settings groups that should NOT be overwritten by values in User and Additional settings. For example: General,Application,ExtraApplicationToLaunch
  --launcher-ignore-user-additional-settings      Ignore additional user settings
  --launcher-generate-exec-wrapper-script         Generate executable wrapper script allowing to set the environment
  --launcher-generate-template                    Generate an example of setting file

at ChildProcess.exithandler (node:child_process:409:12)
at ChildProcess.emit (node:events:513:28)
at maybeClose (node:internal/child_process:1112:16)
at ChildProcess._handle.onexit (node:internal/child_process:304:5)] {
  code: 1,
  killed: false,
  signal: null,
  cmd: '/Applications/Slicer.app/Contents/bin/PythonSlicer -I /Users/admin/.vscode/extensions/ms-python.python-2023.8.0/pythonFiles/get_output_via_markers.py /Users/admin/.vscode/extensions/ms-python.python-2023.8.0/pythonFiles/interpreterInfo.py'
}

VSCode’s interpreter check failure is fixed in recent Slicer Preview Releases. Let us know how it works.

Unfortunately, it is not fixed in Slicer 5.4.0

For reference, this was tentatively fixed in this commit:

@wrc To help us understand, was the fixed we integrated working and did it recently started to fail again?

In windows PC, it was fine. But in MacOS, it showed the same error in Slicer 5.4.0.

Thanks for the follow up.

If I understand your comment, the fix originally integrated fixed the issue on Windows but never fixed it on macOS ?

We are trying to understand if this is a recent regression or not. So any additional details would be helpful.

After the fix integrated by @lassoan and linked above, did it ever work on macOS using the Preview build ?

Could you include screenshot and step by step to illustrate how you configure the interpreter in VS Code ?

Sorry, I don’t know whether this problem has been solved before. I haven’t found the link to download the previous preview build (2023.5.18) so that I cannot test it. Here is the screenshot:
click 3.9.6 64-bit


click enter interpreter path…

input the path of PythonSlicer

VS Code added a whole lot more operations to the interpreter check, which would require some more work to succeed. The “fix” in Slicer-5.4 should prevent Slicer instances to get started and get stuck with a popup, but not sufficient for VS Code current interpreter checks to complete successfully.

Getting a successful interpreter check would make a big difference when all the pyi files from VTK, ITK, Slicer, etc. are properly installed because we could then have auto-complete, documentation, etc. in the code editor. So, we should fix the interpreter check it when we have the pyi files in the Slicer installation package.

when all the pyi files from VTK, ITK, Slicer, etc. are properly installed

For reference, this is tracked in the following issue: