Calling python script gets 'Syntax Error: no viable input...'

Hello all,
I need to call a python script from my macro. I saved the script in the plugins folder, and manually called it from the Plugins dropdown. At first I got the “Syntax Error: no viable input…”. This pointed to a print(f’…’) statement so I converted those to print without the formating.

After that, now the script fails at the very beginning with:
ImportError: No module named numpy

Just wondering if this is going to be an uphill task with jython, or if there is a way to make it run like the script runs on cmdline. Really appreciate any help!

Thanks
Darshat

Hi Darshat,

You want to use the macro-recording to call your python script within a macro right ?

Then your python script has to be written according to the Python2 syntax and you wont have access to the usual python packages, only the standard library.
However you can access all the Java and Fiji libraries.
See the wiki documentation

You can eventually use a call to the command line within the macro (using exec()or so), that would run a local python installation with the script of interest. But this sounds complicated and not very efficient as you wont be able to communicate between the macro and the python script else than via files.

Hello Laurent -

Just to clarify, you can have access to pure python packages
(provided that they are python 2) from outside the standard library
if you make them available by putting them in a jar file in Fiji / Image’s
jars/Lib directory.

(“Pure python” means that the packages can’t have, for example,
a back end written in C, so some very common, useful things like
numpy are out.)

Thanks, mm

1 Like