No module named os


I am trying to learn ImageJ jython scripting, but I cannot seem to import basic module like os: I’m getting an ImportError: No module named os.
I use Fedora 23 and I’ve tried both the distribution packaged imagej and the version downloaded from imagej’s website. I’m guessing my problem is very basic but couldn’t find help on this issue. Can someone point me in the right direction ?

Thanks !

Hi @nicoco

I cannot reproduce the problem here.
Can you try to run the following script and give its output?

import os

Here’s with Fedora packaged version:

$ imagej -b 

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

Using the GUI reports the same problem (but less convenient to copy-paste :slight_smile: )

EDIT: a basic print('TEST') in a test script launched this way does work.

Ok it seems like a problem with a Jython installation.
Any chance you would consider using Fiji, which should solve this? Beyond this I am afraid I cannot be much more of help.


Good advice, thanks :slight_smile:
I’m new to the ImageJ ecosystem, I still don’t really understand the differences between ImageJ and FIJI. Anyway, your solution worked.

1 Like

FAQ entry added!


Just to complement the already made answers.

You can’t import the os module because ImageJ downloads only the Jython.jar where FIJI also includes the Jython /lib directory (with Here a screenshot of the *.jar content for comparison:

Here an older related post:

In my application I use the standalone jython *.jar which includes the /lib , too.


Indeed. To clarify:

  • ImageJ1 uses a “bare” Jython without the lib folder. (In other words: it does not use the “standalone” Jython library.)
  • ImageJ2 uses a shaded version of Jython standalone which includes lib. The jython-standalone artifact is an unshaded uberjar and has problems when mixed into the classpath with other projects such as JRuby. (See jython-shaded for technical details.)

In neither case do you need Fiji—you can download vanilla ImageJ2 and it should also work.

1 Like