4444import javax .script .ScriptException ;
4545
4646import org .scijava .Context ;
47+ import org .scijava .command .CommandService ;
4748import org .scijava .log .LogService ;
4849import org .scijava .object .ObjectService ;
4950import org .scijava .plugin .Parameter ;
@@ -65,6 +66,9 @@ public class PythonScriptEngine extends AbstractScriptEngine {
6566 @ Parameter
6667 private LogService logService ;
6768
69+ @ Parameter
70+ private CommandService commandService ;
71+
6872 public PythonScriptEngine (final Context context ) {
6973 context .inject (this );
7074 setLogService (logService );
@@ -78,10 +82,13 @@ public Object eval(final String script) throws ScriptException {
7882 .filter (obj -> "PythonScriptRunner" .equals (objectService .getName (obj )))//
7983 .findFirst ();
8084 if (!pythonScriptRunner .isPresent ()) {
85+ // Try to help user by running OptionsPython plugin
86+ if (commandService != null ) {
87+ commandService .run (OptionsPython .class , true );
88+ }
8189 throw new IllegalStateException (//
82- "The PythonScriptRunner could not be found in the ObjectService. To use the\n " +
83- "Python script engine, you must call scyjava.enable_scijava_scripting(context)\n " +
84- "with this script engine's associated SciJava context before using it." );
90+ "The PythonScriptRunner could not be found.\n " +
91+ "To use the Python script engine, you must launch your application in Python mode." );
8592 }
8693 return pythonScriptRunner .get ().apply (new Args (script , engineScopeBindings ,
8794 scriptContext ));
0 commit comments