h2o failed to connect when called from R: Java version missmatch

时光总嘲笑我的痴心妄想 提交于 2020-01-11 09:41:30

问题


h2o was working before on my laptop, but I didn't use it for a while (and have installed new packages and updated things in the meantime). Yesterday I tried using it, but it didn't work. I erased the R h2o packaged and I've reinstalled h2o from scratch with

install.packages("h2o")

I tried running h2o with h2o.init() but it gives me this error

java version "9"
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)

Starting H2O JVM and connecting: ............................................................ 
[1] "localhost"
[1] 54321
[1] TRUE
[1] -1
[1] "Failed to connect to localhost port 54321: Connection refused"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (7) Failed to connect to localhost port 54321: Connection refused
[1] 7
Error in h2o.init() : H2O failed to start, stopping execution.

When I look at the error log it shows

Only Java 1.6-1.8 supported, version is 9

I tried to look for more info and I think the error is triggered by this code on line 1836:

if (version != null && !(version.startsWith("1.6") || version.startsWith("1.7") || version.startsWith("1.8"))) {
  System.err.println("Only Java 1.6-1.8 supported, version is " + version);
  return true;

So it seems h2o is checking for a version that starts with 1.6, 1.7 and 1.8 but my version for some reason starts with 9! However, on the terminal, java -version gives

openjdk version "1.8.0_121"
OpenJDK Runtime Environment (Zulu 8.20.0.5-macosx) (build 1.8.0_121-b15)
OpenJDK 64-Bit Server VM (Zulu 8.20.0.5-macosx) (build 25.121-b15, mixed mode)

and which java gives

/Users/myusername/anaconda3/bin/java

------------ EDIT -------

More info: /usr/libexec/java_home -V gives

Matching Java Virtual Machines (4):
    9, x86_64:  "Java SE 9" /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home
    1.8.0_144, x86_64:  "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
    1.8.0_51, x86_64:   "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home
    1.8.0_25, x86_64:   "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home

Which explains the 9 that h2o is seeing. I find it weird that it expects 1.x.0 but the version is just 9. In any case, it seems I need to point that h2o.init() command to the 1.8 java, but I couldn't figure out how to do it.

I usually use brew to install most things, but I never use java so I don't know anything about the versions.

Thanks and best!


回答1:


The error you reported says:

Only Java 1.6-1.8 supported, version is 9

Seems like you have Java 9 installed, which is not yet supported by H2O. Use a compatible version of Java and that will fix the error.

If you can't or don't want to uninstall Java 9, then you'll need to tell H2O which Java you'd like to use by setting the JAVA_HOME environment variable. First, get the location of Java 1.8 by executing the following in a shell:

/usr/libexec/java_home -v 1.8

On my mac, it shows me this:

/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home

You can check if R can see your JAVA_HOME variable by running the following command: Sys.getenv("JAVA_HOME").

If that's blank (and possibly will be if you're using RStudio), then will have to do a bit more work to get R to see the JAVA_HOME variable. You can edit the ~/.Renviron file to add JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home or whatever that location is on your machine. Then restart RStudio and it should work.




回答2:


I followed the discussion in this thread to get a solution to the problem, though it won't be that convenient for some people.

The default java is 1.8.x, hence once that h2o can use, but calling h2o from R results in the version 9 java getting called.

The (rather patchy) solution for now is to start the h2o server from the terminal like this

cd h2o-3.14.0.3   #navigate to wherever you have the h2o installation
java -jar h2o.jar

with that running fine, I then link it from R without starting an h2o instance:

h2o.init(startH2O = FALSE) 

This works fine if you're ok with starting h2o from the terminal (might be the only way if you're working on a cluster), but might be annoying if you want to start it from RStudio right away.



来源:https://stackoverflow.com/questions/46490290/h2o-failed-to-connect-when-called-from-r-java-version-missmatch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!