Using ImageJ in Jupyter notebooks without Anaconda

My institute has a goal of making data more accessible for the customers. The idea is that we should use Jupyter notebooks to present browsable data and provide interactive plots of relevant measurements. I agree that this is a good idea, but I have close to zero experience with notebooks or Python. I see this as an opportunity to learn something useful.

I found the tutorials for using ImageJ in notebooks at GitHub - imagej/tutorials: ImageJ programming examples to be a promising start, but am struggling to get them to work.

My problem is simply getting the necessary frameworks installed. Since our institute is based on contract research, we come under Anaconda’s definition of commercial use, and are since 2020 therefore required to license it. My company’s interpretation of the terms and response to that is simply “do not use Anaconda anymore” and “anything you can do with Anaconda you can also do without it”. The problem is how to do the latter when you are a newbie. Almost all instructions I find when looking at the install instructions for the many dependencies just start with “1) install Anaconda” and there are no details provided for how to do stuff without it.

I have got this far until I got stuck:

I have installed Python and Jupyter and and necessary python modules such as pyimagej using pip.
I am able to get pure Python-based example code running properly, such as the initial examples in the Python-based notebook at tutorials/6-ImageJ-with-Python-Kernel.ipynb at d3ff8e818bb26cb4713371878b239b36cb7d4877 · imagej/tutorials · GitHub

The problem starts as soon as I try to run anything that depends on java. The example notebook works until [24], which uses jnius. pip install jnius does not work at all, but a websearch suggested I do pip install pyjnius instead and that installed without errors. I have set the required environment variables pointing to the Java 8 JDK folder (inside Fiji). The pyjnius hello-world example works from the command line. But jnius does not work in the Jupyter notebook; I get an error message that the JVM could not be started. Are the environment variables perhaps not passed properly from the OS to the notebook? How can I check that?

The other problem I have is getting the Groovy kernel available to Jupyter. I installed BeakerX using pip but Jupyter still shows no other kernel than Python 3 available, so all the other notebooks in the tutorial do not work at all, as expected.

Does anyone know about possible solutions here, that do not require Anaconda?
I am using Windows 10/64 but I don’t think that is the primary problem here.

Stein

It’s very important to know that Anaconda and conda are two different things. conda is an open source package manager that you can use free of cost or restriction. Anaconda is a complete distribution, meaning a bundle of Python and many scientific packages that has been compiled and tested for consistency by the folks at Anaconda, Inc. This quality control and server uptime is what they are asking companies to pay for. This FAQ makes it clear that it is the distribution that they are charging for.

conda, however, can install from many channels, including conda-forge, which is free and community-built, and has a community-built jnius package. So you can install miniconda, configure conda to download from conda-forge by default, and you’re off.

Note also that there is a fully-compatible implementation of conda called mamba, as well as a community-created miniconda that is pre-configured to search from conda-forge called miniforge.

You can read more about mamba and alternative conda implementations here.

All in all, the scientific Python community has your back!

There is one caveat to everything I just said which is that, as far as I know, the server space used by conda-forge is provided by Anaconda, Inc. I’m 90% sure that the new terms of use do not apply to downloading conda-forge packages, but not 100% sure. I’ll try to verify this and write back here. Edit: see below. As a community effort, conda-forge packages remain free to use for everyone, despite being hosted on Anaconda servers.

2 Likes

Confirmation from Peter Wang, the CEO of Anaconda, Inc, that the new terms of service do not apply to conda-forge packages:

2 Likes

@jni, Thank you for this detailed reply!

Yes I had a suspicion that this is the case, but I could not read that clearly from the FAQ.

Getting this confirmed is very useful! That means that I can simply install miniconda, point it to conda-forge; install packages as required with the conda command, and thus get the exact same packages/functionality as I would get if using Anaconda? Or might the packages from the conda-forge channel be different? And should I use miniforge instead of miniconda to be on the safe side?

This should hopefully solve my problems with regards to the non-working beakerx and jnius packages as installed by pip.

1 Like

That means that I can simply install miniconda, point it to conda-forge; install packages as required with the conda command, and thus get the exact same packages/functionality as I would get if using Anaconda? Or might the packages from the conda-forge channel be different? And should I use miniforge instead of miniconda to be on the safe side?

These are not exactly the same thing. The packages on the defaults channel are built using compilation recipes created by Anaconda, and (I believe) fall under the TOS. The packages on the conda-forge channel are built using open recipes, defined in https://github.com/conda-forge/<package-name>-feedstock, and maintained by the community.

Having said that, the recipes in conda-forge are excellent, the conda-forge community is amazing, and everything should work well using those. :+1:

And yes, you should probably use miniforge to be on the safe side. If you accidentally install something from defaults, you are probably in breach of the TOS. It’s much harder to do this unintentionally with miniforge. Having said all this, the Anaconda folks are lovely and I very much doubt they would hound you over a few accidental installs. :sweat_smile: But yes, use miniforge!

@jni , thanks for this clarification. I’ll try miniconda then, and see if that works better than pip. My company tries as hard as possible to not break any licensing terms, so using miniconda should be safe.

Hi @steinr,

Please note that the latest version of pyimagej (1.0.0) uses jpype now instead of pyjnius, which should make installation and running from notebooks much easier.

See this tutorial notebook on the pyimagej repository for the latest version (the one on imagej/tutorials needs to be updated or removed, I guess…):

Also have a look at the repository for the last #i2k workshop at #i2k2020 which contains more material:

2 Likes

Thanks, @imagejan !
The installation of the pyimagej environment removed jupyter and skimage, so it did not work out of the box. So I just reinstalled them using

conda install jupyter notebook
conda install scikit-image

Now the example notebook works fine, without the jnius issues :slight_smile:

2 Likes

I threw away my existing Python and related installations and have reinstalled everything with miniforge today. It works really well ! It is easy to install stuff, and it is much easier to get an overview of what is installed and in what version. The dependency handling is excellent and the error messages are also far more informative. Now I have nearly everything in the tutorial notebooks working (using the scijava environment), except for the Python-based workbook 1-6 which depends on jnius. The updated notebook @imagejan linked to works fine though, also when using the scijava environment per the tutorial installation instructions. So, as far as I can see, the tutorial notebook 1-6 can be replaced with the new version; they seem to be identical in functionality.

Thanks for the great help, @jni and @imagejan !

2 Likes