Writing and running IJ scripts in Jython, externally

imagej

#1

Is this possible?

Right now I’m tabbing back and forth between PyCharm for writing, which has support for Python, but none for Java, and Fiji, which can actually run the scripts, and I don’t really find this ideal, as Fiji’s

I’ve tried to install Jython from source, and I can run “jython” successfully from the terminal, but both PyCharm and VSCode say either the jython binary or the Fiji jython-shaded can’t be executed.

I’ve tried searching around, but it appears that the internet generally doesn’t care about Jython.


#2

Dear @komodovaran,

does PyCharm support Run Configurations? If that’s the case, you could try to create a Run Configuration that actually calls the ImageJ executable with the name of the current Python file? But that’s actually just an idea and I don’t know how well it will work in practice.

Best,
Stefan


#3

I usually use Eclipse with pydev to debug and launch with jython.
I am trying to remember how I have had setup the Eclipse Environment to work with jython (I configured it a year ago…), for sure:

  1. install Eclipse with pydev
    http://www.jython.org/jythonbook/en/1.0/JythonIDE.html

  2. then in the preferences->interpreters be sure to set the jython.jar as Jython Interpreter (you can also have different interpreters for different project if you need)

  3. add ij.jar to the pythonpath of your project (right click on your project and properties)
    47

  4. in your project you can put some lines like that to launch your fiji with your plugins



if __name__ in ['__builtin__', '__main__']:
    from java.lang import System
    from ij import ImageJ
    pluginsDir2 = "/Applications/Fiji.app/plugins";    
    System.setProperty("plugins.dir", pluginsDir2);
    ImageJ(); #this will launch ImageJ GUI
    run() #do something
  1. Eclipse gives you the possibility to launch your project with Configurations as @stelfrich for sure like for setup the maximum java heap size, but I really think it can work even if you need to launch it with arguments inputs
    29

I hope it is helpful and it’s addressing someway to your question
and I stay with you that jython “but it appears that the internet generally doesn’t care about Jython” :wink:

So I really don’t know if this is the most elegant way, but it works :wink:

I’ve never tried with PyCharm …

Emanuele MArtini


Python scripts with imageJ
Debug Fiji Plugin va Netbeans