Search code examples
pythonjythonimagej

Installing a python script in ImageJ


I’m trying to install a Python script in ImageJ. My preference is to use the script with ImageJ 1.x but can use Fiji if required. 

I am trying to use the script with ImageJ 1.x by placing it in the plugins folder.  The script appears in the plugins menu but when I try to run it I get an error that it can't find __future__

Traceback (most recent call last): 
File "<string>", line 1, in <module> 
ImportError: No module named __future__

  This makes no sense to me as the __future__ module is being used to import the with_statement module and python version is listed as :

2.5.4rc1 (2.5:723492dbab02, Feb 8 2013, 10:13:55) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)]

from __future__ import with_statement is specifically designed for use with Python versions 2.5.x

https://docs.python.org/3/library/future.html

So ... moving on ...

I tired to use Fiji instead since it is based on ImageJ2. 

I'm able to paste the code into the Script Editor using File > New > Script ...

The code runs when executed from there.  However, when saved I can't get it to show up in the plugins menu.  I've tried saving it to :

Fiji/plugins

Fiji/plugins/Scripts

Fiji/plugins/Scripts/Plugins

The file name has an _ in it.

The version of Fiji I'm running is ImageJ 2.0.0 rc-68/1.52e / Java1.8.0_172 (64-bit)

The version of ImageJ 1.x I'm running is ImageJ 1.52e / Java1.8.0_172 (64-bit)

Any help would be greatly appreciated.

Thanks


Solution

  • The canonical place to put scripts for ImageJ2 is scripts/Foo/Bar/My_Script.py, if you want it located in the menu at Foo > Bar > My Script.

    It also works for backwards compatibility to use plugins or plugins/Scripts. However, there was recently a critical bug preventing scripts from appearing in the plugins-based locations; see this thread. The bug is fixed in the latest release.