I have a python package for FIJI that I’ve been bundling up in a .jar file for easy distribution to other members in our lab (per https://imagej.net/Jython_Scripting). The recent major updates to FIJI completely busted my scripts in a most perplexing way… I could run a script once, and thereafter I would get:
ImportError: no module named “<mymodule>”
After quite a bit of fussing today, I’ve managed to narrow down the problem to a very particular set of conditions:
The package must be bundled as a .jar. The equivalent package structure of .py files copied to jars/lib does not cause this error to occur.
The package name/structure begins with com. or org. … packages beginning with net., gov., edu., com2., woof., etc. do not produce this error.
I made a little demo .jar to demonstrate the problem, with the following structure (every folder has the necessary empty init.py):
FIJI.app/jars/ -- bugtest.jar -- com/ -- bug/ -- hello_com.py -- woof/ -- bug/ -- hello_woof.py
Both .py files contain the same two lines:
from ij import IJ IJ.showMessage(“COM”) # or WOOF
With that .jar installed, I open the jython editor and run the following script:
from woof.bug import hello_woof from com.bug import hello_com
On a Win64 installation, I run it once, and I get both popup messages. Press run a second time, and I’ll get the first expected popup message (“WOOF”), but afterwards I get
ImportError: No module named bug. It can no longer find the same module (com.bug) it just used moments ago! If I copy the script to another instance of the script editor, it will fail the first time with the same error. This also happens if I change the module name to “org.bug”, but not with other TLDs like “net” or “gov”.
Very strangely, on my MacOS installation, only a module starting with “org.” fails on second run, whereas a “com.” module can run repeatedly… unless the script also includes the line “
import shutil”. Then “com.” will also give the same ImportError on second pass.
As mentioned above, if I directly copy the source .py files into jars/lib and do not use a .jar file, this error does not occur.
This is getting beyond my technical understanding, but I’m guessing something is happening to the python/jython path during execution that breaks modules that begin with “com.” or “org.”? Is there some limitation to package naming conventions for jython?
To be clear, an older FIJI build with these jars runs the above OK:
Selectively upgrading to these jars (+ dependences) results in error:
jython-shaded-0.0.0-STUB jython-slim-2.7.2 scripting-jython-1.0.0
I was trying to be proper and use the reverse domain name naming convention for my package, but I suppose my workaround for now is to drop the “com.”