Pyimagej on google colab

Hi, pyimagej is very nice.

I tried to use pyimagej on colab.
(reference:How do I install pyimagej?)

My scripts are;

# install JDK8 in colab
import os       #importing os to set environment variable
def install_java():
  !apt-get install -y openjdk-8-jdk-headless -qq > /dev/null      #install openjdk
  os.environ["JAVA_HOME"] = "/usr/lib/jvm/java-8-openjdk-amd64"     #set environment variable
  !java -version       #check java version

install maven current version

!sudo apt-get install maven

install pyimagej and cython

!pip install Cython pyimagej

install pyjnius (to /usr/local in colab runtime)

!wget && tar -xjf pyjnius-1.2.0-py37h90b5fae_0.tar.bz2 -C /usr/local
# set env
os.environ["PYJNIUS_JAR"] = "/usr/local/share/pyjnius/pyjnius.jar"

let’s use ij

import imagej;
ij = imagej.init(); 

check feature,

from skimage import io
import numpy as np

url = ''
img = io.imread(url)
img = np.mean(img, axis=2)

pyimagej on colab is so great.
GPU freeeee.



Awesome, thanks @11110 for this nice guide! I linked it from pyimagej’s README:


Hi, Mr.Alexandre,

Could you try this ?
I think that an error encountered by imglyb-0.4.0, so I replaced to 0.3.5 version.



(Attachment pyimagej_Success.ipynb is missing) (168.2 KB)

Hello Mr.TaTsuaki,

It does work now with the change of version, thank you very much for your quick reply.

Have a good day,


If I wanted to run my plugins in Colab. Would it be enough to upload my local Fiji distribution to Google drive and call:

ij = imagej.init(“my/local/Fiji.App”)

I am doing this and I am not able to use jnius.autoclass



You are pioneer. (lol)
I tried it, and one simple way found.
Could you try it ?

2020年5月9日(土) 1:25 Carlos via Forum <>: (329 KB)

Thanks for the answer!
That also allows me to run my Fiji distribution. However I am still not able to instansiate a java class using jnius.autoclass.
It says:

JavaException: JVM exception occurred: ij/WindowManager java.lang.NoClassDefFoundError

Ive looking and it seems that the jdk version being installed is the 11.0.7 (as far as I remember you need to login into Oracle to download versions that are not the latest).
Could this be a problem?


ij/WindowManager java.lang.NoClassDefFoundError

Maybe I think that is X11 related error. (this error is correct error)
Google Colaboratory does not have GUI, so you can not use window related java classes.
But, IJ has headless mode, perhaps, there’s a chance you can use it’s mode.
I do not know how to do that. sorry…

2020年5月12日(火) 20:36 Carlos via Forum <>:

1 Like

Hi @carlosuc3m,

I tried the solution of @11110 and adapted it to the specific problem of using clij on Colab. Everything seems to work so thanks @11110!

You can test it directly here on Colab:

You can skip the part where I install clij of course. And don’t forget to “Restart runtime” before actually using Fiji (in the section clij via macro). Also before anything, don’t forget to change the Runtime type to GPU.

Good luck,


Thanks a lot. It works perfectly! What happened is that I forgot to restart the runtime after installing the packeges and setting the environment variables.
Thanks again @guiwitz and @11110 !!