Interoperability issues with pyimagej (1.0.0) and pyjnius (1.2.2 & 1.3.0)

Hello everyone,

I am trying to get started with running CLIJ2 or CLIJx from command line in a Python script in order to circumvent an issue with doing so from macros.

Currently, running on Ubuntu 18.0.4, I have installed pyimagej with miniconda by running conda create -n pyimagej -c conda-forge openjdk=8 pyimagej and pyjnius via pip by running python -m pip install pyjnius==1.3.0 after activating the pyimagej virtualenv.

Separately, pyimagej and pyjnius appear to work as I can successfully execute the following Hello World scripts.

import imagej
ij = imagej.init("/home/analysis/Fiji.app/")
ij.getVersion()

with 2.1.0/1.53c returned, and in a new REPL instance running

from jnius import autoclass
autoclass("java.lang.System").out.println("Hello World")

prints Hello World.

If both are run together in the same REPL instance, the following traceback is returned.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/analysis/Desktop/Albert/dependencies/miniconda3/envs/pyimagej/lib/python3.8/site-packages/jnius/__init__.py", line42, in <module>
    from .reflect import * #noqa
  File "/home/analysis/Desktop/Albert/dependencies/miniconda3/envs/pyimagej/lib/python3.8/site-packages/jnius/reflect.py", line 20, in <module>
    class Class(with metaclass(MetaJavaClass, JavaClass)):
  File "/home/analysis/Desktop/Albert/dependencies/miniconda3/envs/pyimagej/lib/python3.8/site-packages/six.py", line 856, in __new__
    return meta(name, resolved_bases, d)
  File "jnius/jnius_export_class.pxi", in line 118, in jnius.MetaJavaClass.__new__
  File "jnius/jnius_export_class.pxi", in line 178, in jnius.MetaJavaClass.resolve_class
  File "jnius/jnius_env.pxi", line 11, in jnius.get_jnienve
  File "jnius/jnius_jvm_dlopen.pxi", line 132, in jnius.get_platform_jnienv
  File "jnius/jnius_jvm_dlopen.pxi", line 126 in jnius.create_jnienv
SystemError: JVM failed to start: -5

My JAVA_HOME is set to /home/analysis/Desktop/Albert/dependencies/miniconda3/envs/pyimagej and JAVA_LD_LIBRARY_PATH to /home/analysis/Desktop/Albert/dependencies/miniconda3/envs/pyimagej/jre/lib/amd/64/server.

I had also tried rolling pyjnius back to 1.2.2 and setting JVM_PATH to the location of my libjvm.so, and rolling pyimagej to 0.5 but hit a ModuleNotFoundError for ‘scyjava_config’ and have not continued on that route.

I’m wondering if the pyimagej switch from pyjnius to jpype has something to do with older examples of pyjnius autoclassing usage now erroring (for me).

Hey Albert @dekdaas ,

I’m not so much a pyjnius expert, but if you want to use GPU-accelerated image processing based on OpenCL from python, you could give clEsperanto a try. It is the upcoming CLIJ successor that runs in python and does not need a pyjnius, pyimagej or ImageJ installation. If you need help translating a macro to python, I’m happy to assist. Just let me know!

Cheers,
Robert

You shouldn’t have pyjnius in your environment at all when running pyimagej-1.0.0, as it builds entirely on jpype now.

I guess they conflict because both pyjnius and jpype (or scyjava or imglyb for that matter) will try to start a Java Virtual Machine (JVM) when initialized.

3 Likes

Robert,
Thanks for the tip, I’ve since ported our macro over to clEsperanto and it’s solved all my JVM headaches. Thank you for your work in the Python ecosystem!

1 Like