2

I am trying to connect a headless imageJ library to my python application. Unfortunately, the dependency error list goes on endless and I am now stuck at an import error involving the import of a java wrapper called jnius.

So far I have installed: wheel, imagej, cython, imglyb, pyjnius modules using an updated pip. Since the "Unable to determine JDK_HOME" was triggered in between, I followed the obvious rules of updating environment Variable list to my paths (both user and system). In between, pyjnius reported "Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools" and I installed the same (a hefty 5.63 GB) and additionally the "VCForPython27".

import os
print(os.environ.get('JAVA_HOME'))
print(os.environ.get('JDK_HOME'))

both the command gives me the following output:

C:\Program Files\Java\jdk-11.0.2; C:\Program Files\Java\jdk-11.0.2\bin;C:\Program Files\Java\jdk-11.0.2\bin\server

Now I can import imageJ in my code, but when I try to use its first function

ij = imagej.init('C:\\Users\\Documents\\ImageJ_Fiji\ImageJ-win64.exe')

I get the following error associated with import scyjava as: "Unable to import scyjava dependency jnius." and when I try to run pip install jnius --user I get the same old error: "Unable to determine JDK_HOME'" which seems confusing since I had successfully installed pyjnius and a pip install scyjava --user gives me an output that all requirements are satisfied.

I am no longer using a conda environment (since it got me very confusing), my python version is 3.7.2 and my OS is windows 10. The editor I use is PyCharm. I have installed the latest JDK and JRE from oracle website.

Referance: Jnius installation bug, "Unable to determine JDK_HOME" jnius 1.1 import error

abk
  • 135
  • 1
  • 13

2 Answers2

2

Installation of pyimagej has been discussed on the image.sc forum, e.g. in this topic.

Also, there are currently a few open issues/PRs in scyjava (#5 and #7) and pyimagej (#21).

As far as I understand, the recommended way to install imagej in Python is using conda, as activating the environment with conda activate imagej will set the required environment variables for the dependencies.

For further questions, I recommend asking on the image.sc forum.

Jan Eglinger
  • 3,876
  • 1
  • 22
  • 49
0

There are working condition need to be satisfied, along with installing Java (JDK), Maven and python packages Cython, pyjnius, scyjava, imglyb, and pyimagej.

1) Environment variable JAVA_HOME point to the JDK directory.

In your case C:\Program Files\Java\jdk-11.0.2. I think the redundancy (*/bin, JDK_HOME etc.) should not harm.

2) Environment variable Path contains directory of JDK binaries and Maven binaries.

e.g. for Java it is C:\Program Files\Java\jdk-11.0.2\bin. When installing or compiling pyjnius, you are likely need them.

3) Hava pyjnius.jar located somewhere and set environment variable PYJNIUS_JAR to point to it, so that scyjava can find it.

The error "pyjnius JAR not found" and "Unable to import scyjava dependency jnius." correspond to this step. So you are likely missing the (undocumented) step (3).

Step (3) is currently automatically done if you are using conda. Otherwise you need to download pyjnius.jar separately somewhere. See discussion here. Note that without pyjnius.jar the python module jnius will still functioning, but somehow scyjava still need that jar file.

Eddy Xiao
  • 181
  • 1
  • 6