Failing to shell 'Python interactive console' from Basic under Linux

The following code operates fine under Windows but fails under Linux:

Sub interpreter_console
    ps = CreateUnoService("com.sun.star.util.PathSettings")
    install_path = ConvertFromURL(ps.Module)
    Shell( install_path + GetPathSeparator() + "python" )
End Sub

Note that the shelled pgm file exists, and that same pgm argument runs fine from the OS terminal.

Same observations with this code:

Sub Main
	flags = com.sun.star.system.SystemShellExecuteFlags
    ps = CreateUnoService("com.sun.star.util.PathSettings")
    install_path = ConvertFromURL(ps.Module)
    pgm = install_path + GetPathSeparator() + "python"
	sys = CreateUnoService("com.sun.star.system.SystemShellExecute")
	sys.Execute( pgm, " ", flags.DEFAULTS)
End Sub

sorry my fault

Are you sure? What does pgm and specifically install_path expand to?

On Windows, LibreOffice bundles Python because usually there’s no Python on Windows and to make sure that a correct Python version is used.
On Linux that is not necessary and the system’s installed python can be used, so usually there is no python executable in the LibreOffice installation paths.

You’re perfectly right ! This is the case for OS packaged copies of LibreOffice.

Whenever LibreOffice comes as a TDF bundle, AppImage, and the like … Python comes embedded in LibreOffice. These are the cases my code samples relate too.

in this case the code can be simplified to something like:

Sub interpreter_console
    Shell( "lxterminal -e python3" )
End Sub

Also I would like to recommend ‘ipython3’ instead of the normal ‘python3’!

Usin GNU/Linux the code becomes:

Sub interpreter_console
    ps = CreateUnoService("com.sun.star.util.PathSettings")
    install_path = ConvertFromURL(ps.Module)
    Shell( "x-terminal-emulator -e " + install_path + GetPathSeparator() + "python" )
End Sub

x-terminal-emulator substitutes:

  • konsole under KDE
  • gnome-terminal under Gnome
  • lxterminal under Lxde
  • qterminal under LxQt
  • mate-terminal under Mate
  • and so on …

Thx to Olivier H