Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to guess the Java version/Failed to bootstrap the artifact. #267

Closed
BrandonUL opened this issue Jun 22, 2023 · 6 comments
Closed
Labels
tech-support Need help to get things working

Comments

@BrandonUL
Copy link

BrandonUL commented Jun 22, 2023

Hello! I am brand new to pyimagej and after about an hour or so of debugging I am reaching out for some help!

Per the tutorial I first ran:

python -c 'import imagej; ij = imagej.init("2.5.0"); print(ij.getVersion())'

which returns:

Failed to guess the Java version.
Failed to bootstrap the artifact.

Possible solutions:
* Double check the endpoint for correctness (https://search.maven.org/).
* Add needed repositories to ~/.jgorc [repositories] block (see README).
* Try with an explicit version number (release metadata might be wrong).

Full Maven error output:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/site-packages/imagej/__init__.py", line 1202, in init
    raise RuntimeError("Failed to create a JVM with the requested environment.")
RuntimeError: Failed to create a JVM with the requested environment.

I could not find a specific fix online besides updating mvn but when I attempted to anaconda told me my mvn package was up to date, so I next ran:

!python -c 'import imagej; print(imagej.__version__)'

which returned

1.4.1

Knowing that it wasn't the up to date version I attempted to use the legacy version with the following code:

import imagej
ij = imagej.init('1.4.1')

which returned the following:

Failed to guess the Java version.
Failed to guess the Java version.
System call to java failed
Traceback (most recent call last):
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/site-packages/scyjava/_java.py", line 148, in jvm_version
    output = subprocess.check_output(
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/subprocess.py", line 421, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/Users/brandonulin/anaconda3/envs/pyimagej/jre/bin/java', '-version']' died with <Signals.SIGKILL: 9>.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/site-packages/imagej/__init__.py", line 1318, in _create_jvm
    if hasattr(sj, "jvm_version") and sj.jvm_version()[0] >= 9:
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/site-packages/scyjava/_java.py", line 152, in jvm_version
    raise RuntimeError("System call to java failed") from e
RuntimeError: System call to java failed
System call to java failed
Traceback (most recent call last):
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/site-packages/scyjava/_java.py", line 148, in jvm_version
    output = subprocess.check_output(
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/subprocess.py", line 421, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/Users/brandonulin/anaconda3/envs/pyimagej/jre/bin/java', '-version']' died with <Signals.SIGKILL: 9>.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/site-packages/imagej/__init__.py", line 1318, in _create_jvm
    if hasattr(sj, "jvm_version") and sj.jvm_version()[0] >= 9:
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/site-packages/scyjava/_java.py", line 152, in jvm_version
    raise RuntimeError("System call to java failed") from e
RuntimeError: System call to java failed
ImageJ2 version given: 1.4.1
ImageJ2 version given: 1.4.1
Adding jars from endpoints ['net.imagej:imagej:1.4.1', 'net.imagej:imagej-legacy:MANAGED', 'org.scijava:scijava-config:MANAGED', 'io.scif:scifio-labeling:0.3.1', 'net.imglib2:imglib2-imglyb:1.1.0']
Adding jars from endpoints ['net.imagej:imagej:1.4.1', 'net.imagej:imagej-legacy:MANAGED', 'org.scijava:scijava-config:MANAGED', 'io.scif:scifio-labeling:0.3.1', 'net.imglib2:imglib2-imglyb:1.1.0']
Using endpoints ['net.imagej:imagej:1.4.1', 'io.scif:scifio-labeling:0.3.1', 'net.imagej:imagej-legacy:MANAGED', 'net.imglib2:imglib2-imglyb:1.1.0', 'org.scijava:scijava-config:MANAGED']
Using endpoints ['net.imagej:imagej:1.4.1', 'io.scif:scifio-labeling:0.3.1', 'net.imagej:imagej-legacy:MANAGED', 'net.imglib2:imglib2-imglyb:1.1.0', 'org.scijava:scijava-config:MANAGED']
Getting verbose level: 2
Getting verbose level: 2
Getting verbose level: 2
Getting verbose level: 2
Returning expanded coordinate net.imagej:imagej:1.4.1.
Returning expanded coordinate net.imagej:imagej:1.4.1.
Returning expanded coordinate io.scif:scifio-labeling:0.3.1.
Returning expanded coordinate io.scif:scifio-labeling:0.3.1.
Returning expanded coordinate net.imagej:imagej-legacy:MANAGED.
Returning expanded coordinate net.imagej:imagej-legacy:MANAGED.
Returning expanded coordinate net.imglib2:imglib2-imglyb:1.1.0.
Returning expanded coordinate net.imglib2:imglib2-imglyb:1.1.0.
Returning expanded coordinate org.scijava:scijava-config:MANAGED.
Returning expanded coordinate org.scijava:scijava-config:MANAGED.
First time start-up may be slow. Downloaded dependencies will be cached for shorter start-up times in subsequent executions.
First time start-up may be slow. Downloaded dependencies will be cached for shorter start-up times in subsequent executions.
Executing: ('/Users/brandonulin/anaconda3/envs/pyimagej/bin/mvn', '-B', '-f', '/Users/brandonulin/.jgo/net.imagej/imagej/1.4.1/9d8a762fc12617c9e0fc4785a575967ee9ec5d883c92bf45e65e2106e3237a51/pom.xml', 'dependency:resolve', '-X')
Executing: ('/Users/brandonulin/anaconda3/envs/pyimagej/bin/mvn', '-B', '-f', '/Users/brandonulin/.jgo/net.imagej/imagej/1.4.1/9d8a762fc12617c9e0fc4785a575967ee9ec5d883c92bf45e65e2106e3237a51/pom.xml', 'dependency:resolve', '-X')
Failed to bootstrap the artifact.
Failed to bootstrap the artifact.


Possible solutions:
Possible solutions:
* Double check the endpoint for correctness (https://search.maven.org/).
* Double check the endpoint for correctness (https://search.maven.org/).
* Add needed repositories to ~/.jgorc [repositories] block (see README).
* Add needed repositories to ~/.jgorc [repositories] block (see README).
* Try with an explicit version number (release metadata might be wrong).
* Try with an explicit version number (release metadata might be wrong).


Full Maven error output:
Full Maven error output:


---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[15], line 2
      1 import imagej
----> 2 ij = imagej.init('1.4.1')

File ~/anaconda3/envs/pyimagej/lib/python3.10/site-packages/imagej/__init__.py:1202, in init(ij_dir_or_version_or_endpoint, mode, add_legacy, headless)
   1200     success = _create_jvm(ij_dir_or_version_or_endpoint, mode, add_legacy)
   1201     if not success:
-> 1202         raise RuntimeError("Failed to create a JVM with the requested environment.")
   1204 if mode == Mode.GUI:
   1205     # Show the GUI and block.
   1206     if macos:
   1207         # NB: This will block the calling (main) thread forever!

RuntimeError: Failed to create a JVM with the requested environment.

I then tried:

import imagej
import scyjava
scyjava.config.add_option('-Xmx6g')
ij = imagej.init('1.4.1')
Failed to guess the Java version.
Failed to guess the Java version.
System call to java failed
Traceback (most recent call last):
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/site-packages/scyjava/_java.py", line 148, in jvm_version
    output = subprocess.check_output(
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/subprocess.py", line 421, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/Users/brandonulin/anaconda3/envs/pyimagej/jre/bin/java', '-version']' died with <Signals.SIGKILL: 9>.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/site-packages/imagej/__init__.py", line 1318, in _create_jvm
    if hasattr(sj, "jvm_version") and sj.jvm_version()[0] >= 9:
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/site-packages/scyjava/_java.py", line 152, in jvm_version
    raise RuntimeError("System call to java failed") from e
RuntimeError: System call to java failed
System call to java failed
Traceback (most recent call last):
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/site-packages/scyjava/_java.py", line 148, in jvm_version
    output = subprocess.check_output(
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/subprocess.py", line 421, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/Users/brandonulin/anaconda3/envs/pyimagej/jre/bin/java', '-version']' died with <Signals.SIGKILL: 9>.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/site-packages/imagej/__init__.py", line 1318, in _create_jvm
    if hasattr(sj, "jvm_version") and sj.jvm_version()[0] >= 9:
  File "/Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/site-packages/scyjava/_java.py", line 152, in jvm_version
    raise RuntimeError("System call to java failed") from e
RuntimeError: System call to java failed
ImageJ2 version given: 1.4.1
ImageJ2 version given: 1.4.1
Adding jars from endpoints ['net.imagej:imagej:1.4.1', 'net.imagej:imagej-legacy:MANAGED', 'org.scijava:scijava-config:MANAGED', 'io.scif:scifio-labeling:0.3.1', 'net.imglib2:imglib2-imglyb:1.1.0']
Adding jars from endpoints ['net.imagej:imagej:1.4.1', 'net.imagej:imagej-legacy:MANAGED', 'org.scijava:scijava-config:MANAGED', 'io.scif:scifio-labeling:0.3.1', 'net.imglib2:imglib2-imglyb:1.1.0']
Using endpoints ['net.imagej:imagej:1.4.1', 'io.scif:scifio-labeling:0.3.1', 'net.imagej:imagej-legacy:MANAGED', 'net.imglib2:imglib2-imglyb:1.1.0', 'org.scijava:scijava-config:MANAGED']
Using endpoints ['net.imagej:imagej:1.4.1', 'io.scif:scifio-labeling:0.3.1', 'net.imagej:imagej-legacy:MANAGED', 'net.imglib2:imglib2-imglyb:1.1.0', 'org.scijava:scijava-config:MANAGED']
Getting verbose level: 2
Getting verbose level: 2
Getting verbose level: 2
Getting verbose level: 2
Returning expanded coordinate net.imagej:imagej:1.4.1.
Returning expanded coordinate net.imagej:imagej:1.4.1.
Returning expanded coordinate io.scif:scifio-labeling:0.3.1.
Returning expanded coordinate io.scif:scifio-labeling:0.3.1.
Returning expanded coordinate net.imagej:imagej-legacy:MANAGED.
Returning expanded coordinate net.imagej:imagej-legacy:MANAGED.
Returning expanded coordinate net.imglib2:imglib2-imglyb:1.1.0.
Returning expanded coordinate net.imglib2:imglib2-imglyb:1.1.0.
Returning expanded coordinate org.scijava:scijava-config:MANAGED.
Returning expanded coordinate org.scijava:scijava-config:MANAGED.
First time start-up may be slow. Downloaded dependencies will be cached for shorter start-up times in subsequent executions.
First time start-up may be slow. Downloaded dependencies will be cached for shorter start-up times in subsequent executions.
Executing: ('/Users/brandonulin/anaconda3/envs/pyimagej/bin/mvn', '-B', '-f', '/Users/brandonulin/.jgo/net.imagej/imagej/1.4.1/9d8a762fc12617c9e0fc4785a575967ee9ec5d883c92bf45e65e2106e3237a51/pom.xml', 'dependency:resolve', '-X')
Executing: ('/Users/brandonulin/anaconda3/envs/pyimagej/bin/mvn', '-B', '-f', '/Users/brandonulin/.jgo/net.imagej/imagej/1.4.1/9d8a762fc12617c9e0fc4785a575967ee9ec5d883c92bf45e65e2106e3237a51/pom.xml', 'dependency:resolve', '-X')
Failed to bootstrap the artifact.
Failed to bootstrap the artifact.


Possible solutions:
Possible solutions:
* Double check the endpoint for correctness (https://search.maven.org/).
* Double check the endpoint for correctness (https://search.maven.org/).
* Add needed repositories to ~/.jgorc [repositories] block (see README).
* Add needed repositories to ~/.jgorc [repositories] block (see README).
* Try with an explicit version number (release metadata might be wrong).
* Try with an explicit version number (release metadata might be wrong).


Full Maven error output:
Full Maven error output:


---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[16], line 4
      2 import scyjava
      3 scyjava.config.add_option('-Xmx6g')
----> 4 ij = imagej.init('1.4.1')

File ~/anaconda3/envs/pyimagej/lib/python3.10/site-packages/imagej/__init__.py:1202, in init(ij_dir_or_version_or_endpoint, mode, add_legacy, headless)
   1200     success = _create_jvm(ij_dir_or_version_or_endpoint, mode, add_legacy)
   1201     if not success:
-> 1202         raise RuntimeError("Failed to create a JVM with the requested environment.")
   1204 if mode == Mode.GUI:
   1205     # Show the GUI and block.
   1206     if macos:
   1207         # NB: This will block the calling (main) thread forever!

RuntimeError: Failed to create a JVM with the requested environment.

I then tried debugging my self by executing:

import imagej.doctor
imagej.doctor.checkup()

which returns:

Checking Python:
--> Python executable = /Users/brandonulin/anaconda3/envs/pyimagej/bin/python

Checking environment:
--> CONDA_PREFIX = /Users/brandonulin/anaconda3/envs/pyimagej
--> Python executable matches Conda environment.

Checking Python dependencies:
--> jgo: /Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/site-packages/jgo/__init__.py
--> scyjava: /Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/site-packages/scyjava/__init__.py
--> imglyb: /Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/site-packages/imglyb/__init__.py
--> pyimagej: /Users/brandonulin/anaconda3/envs/pyimagej/lib/python3.10/site-packages/imagej/__init__.py

Checking Maven:
--> Maven executable = /Users/brandonulin/anaconda3/envs/pyimagej/bin/mvn
$ mvn -v
Command '['/Users/brandonulin/anaconda3/envs/pyimagej/bin/mvn', '-v']' died with <Signals.SIGKILL: 9>.

Checking Java:
--> JAVA_HOME = /Users/brandonulin/anaconda3/envs/pyimagej
--> Java executable = /Users/brandonulin/anaconda3/envs/pyimagej/bin/java
$ java -version
Command '['java', '-version']' died with <Signals.SIGKILL: 9>.

Great job! All looks good.

Which is a tad confusing since the output seems to have errors but also said Great job! All looks good....

I then ran:

imagej.doctor.debug_to_stderr()

Which returned nothing... and than ran:

imagej.doctor.debug_to_stderr(debug_maven=True)

which returned:

Setting verbose level to 2 (was 2)
Setting verbose level to 2 (was 2)
Setting verbose level to 2 (was 2)
Setting verbose level to 2 (was 2)
Setting verbose level to 2 (was 2)
Setting verbose level to 2 (was 2)
Setting verbose level to 2 (was 2)
Setting verbose level to 2 (was 2)

I am relatively new to coding and can't seem to pinpoint the exact issue. Any and all help would be greatly appreciated as I am excited to use this package for my summer research project!

-Brandon

@ctrueden
Copy link
Member

ctrueden commented Jun 22, 2023

Hi @BrandonUL 👋 Thanks for the report. There are a couple of different issues going on here. I'll try to comment on them one by one.


python -c 'import imagej; print(imagej.__version__)'

Be careful—this command returns the version of PyImageJ (Python piece), not the version of ImageJ2 (Java piece).

As of this writing:

  • 1.4.1 is currently the latest version of PyImageJ, which is the Python side of the project.
  • 2.13.1 is the latest version of the net.imagej:imagej Java library i.e. ImageJ2.

So, your Python environment has PyImageJ 1.4.1 successfully installed, but when it tries to download and initialize the ImageJ2 Java libraries, it runs into problems.

As such, because version 1.4.1 was never a release version of net.imagej:imagej, the line ij = imagej.init('1.4.1') will never work...


System call to java failed
...
subprocess.CalledProcessError: Command '['/Users/brandonulin/anaconda3/envs/pyimagej/jre/bin/java', '-version']' died with <Signals.SIGKILL: 9>.

☝️ That error is bad news... it means that when PyImageJ attempted to invoke java -version, it crashed. I haven't seen this before. 😕

Similarly, from your PyImageJ doctor checkup:

Checking Maven:
--> Maven executable = /Users/brandonulin/anaconda3/envs/pyimagej/bin/mvn
$ mvn -v
Command '['/Users/brandonulin/anaconda3/envs/pyimagej/bin/mvn', '-v']' died with <Signals.SIGKILL: 9>.

Same error. Probably because mvn calls java under the hood, which crashes the same way.


Which is a tad confusing since the output seems to have errors but also said Great job! All looks good....

Agreed—that's a bug in the PyImageJ doctor. We should be catching/noticing that failure and reporting it as a problem with your installation, not ignoring it. I filed #268 to track this bug.


Setting verbose level to 2 (was 2)
Setting verbose level to 2 (was 2)
Setting verbose level to 2 (was 2)
Setting verbose level to 2 (was 2)

It's weird that you're seeing multiple copies of this output. There is only supposed to be one. I filed #269 to track this behavior.


So then finally: the heart of the problem is the SIGKILL crashes from your openjdk installation.

Are you running on Intel/x86-64 Mac? Or M1 Mac?

If it's an M1, then maybe you're getting an x86-64 copy of Java and Rosetta2 is barfing on it?

As a next step, could you try installing OpenJDK 11 via Homebrew, instead of using the conda-forge openjdk?

brew install openjdk@11

If you're not already using Homebrew, I consider it an essential tool for macOS system. See https://brew.sh for details.

Then you just need to set your JAVA_HOME environment variable to point to the installed OpenJDK, which you should find under /usr/lib/jvm somewhere IIRC (it's a Cask).

Once JAVA_HOME is set, you should be able to convince PyImageJ and friends to use it—maybe by doing nothing, or maybe by uninstalling the openjdk package from your Conda environment. The imagej.doctor checkup should tell you whether it's being picked up. Happy to help further if you get stuck! 👍

@ctrueden
Copy link
Member

I was wrong about not having seen the SIGKILL error before... issue #237 reports the same problem. It's the OpenJDK from conda-forge on M1 Macs.

@BrandonUL Please try with different OpenJDKs: v8, v11, and v17 from conda-forge, and v8, v11, and v17 from Homebrew, and report back which ones work, and which ones crash. I would do it myself, but I don't have an M1 Mac to test. (@hinerm if you feel like it, you could also try this)

@BrandonUL
Copy link
Author

Hello,

Thank you for the response! Your response is very helpful and v11 did work. It is now working and can proceed.

@ctrueden
Copy link
Member

@BrandonUL Awesome, glad to hear! Do you mean v11 from conda-forge worked? Or v11 from Homebrew? Just clarifying so that I know what to advise anyone else who has this issue in the future. Thanks!

@Dectective
Copy link

@BrandonUL Awesome, glad to hear! Do you mean v11 from conda-forge worked? Or v11 from Homebrew? Just clarifying so that I know what to advise anyone else who has this issue in the future. Thanks!

I changed openjdk=8 to openjdk=11 and it worked.
Also, I didn't install mamba because it messes with my base environment.
The OS is MacOS 13.4.1. M1 Max 32GB.

Please update the installation instruction to both gitgub and readthedocs.io, thanks!
conda create -n pyimagej -c conda-forge pyimagej openjdk=11
conda activate pyimagej

ctrueden added a commit that referenced this issue Jun 25, 2023
And add notes about how version 8 is broken for M1 Macs.

See #267.
@ctrueden
Copy link
Member

Thanks @Dectective. With 5b8c695, I updated PyImageJ's recommended OpenJDK version from 8 to 11, and added warnings about the problem with openjdk=8 on M1 Macs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tech-support Need help to get things working
Projects
None yet
Development

No branches or pull requests

3 participants