安装期间加载了错误的Java版本

时间:2017-12-13 14:14:44

标签: r windows-10 rjava install.packages

尝试在我的64位Windows 10上安装依赖于Java / rJava的软件包时,我遇到了一个奇怪的问题:

> devtools::install_github("ropensci/tabulizer", INSTALL_opts = "--no-multiarch")
Downloading GitHub repo ropensci/tabulizer@master
from URL https://api.github.com/repos/ropensci/tabulizer/zipball/master
Installing tabulizer
Downloading GitHub repo ropensci/tabulizerjars@master
from URL https://api.github.com/repos/ropensci/tabulizerjars/zipball/master
Installing tabulizerjars
"C:/PROGRA~1/R/R-34~1.2/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL  \
  "C:/Users/binis/AppData/Local/Temp/Rtmpiw2khr/devtools4d7472ae39f9/ropensci-tabulizerjars-60b7cec"  \
  --library="C:/Users/binis/Documents/R/win-library/3.4" --install-tests 

* installing *source* package 'tabulizerjars' ...
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error: package or namespace load failed for 'tabulizerjars':
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: inDL(x, as.logical(local), as.logical(now), ...)
  error: unable to load shared object 'C:/Users/binis/Documents/R/win-library/3.4/rJava/libs/i386/rJava.dll':
  LoadLibrary failure:  %1 is not a valid Win32 application.

Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for 'i386'
* removing 'C:/Users/binis/Documents/R/win-library/3.4/tabulizerjars'
Installation failed: Command failed (1)
"C:/PROGRA~1/R/R-34~1.2/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL  \
  "C:/Users/binis/AppData/Local/Temp/Rtmpiw2khr/devtools4d744e067cae/ropensci-tabulizer-3aad163"  \
  --library="C:/Users/binis/Documents/R/win-library/3.4" --install-tests 

ERROR: dependency 'tabulizerjars' is not available for package 'tabulizer'
* removing 'C:/Users/binis/Documents/R/win-library/3.4/tabulizer'
Installation failed: Command failed (1)

现在我意识到这看起来像是我搞砸了Java版本或路径信息。但事实并非如此(据我所知):

> library(rJava)
> .jinit()
> .jcall("java/lang/System", "S", "getProperty", "java.version")
[1] "1.8.0_151"
> .jcall("java/lang/System", "S", "getProperty", "java.home")
[1] "C:\\Program Files\\Java\\jre1.8.0_151"
> .jcall("java/lang/System", "S", "getProperty", "sun.arch.data.model")
[1] "64"
> .jcall("java/lang/System", "S", "getProperty", "os.arch")
[1] "amd64"

这表明os体系结构和Java体系结构匹配(R也是64位),java.home设置正确,并且rJava在我的机器上运行良好。

现在我不确定我是否正确理解了错误消息,但似乎R正在尝试在安装过程中加载32位版本的rJava失败。我通过在我的机器上将java home更改为32位安装来测试它:

> options(java.home="C:/Program Files (x86)/Java/jre1.8.0_151") #32-bit version
> library(rJava)
Error: package or namespace load failed for ‘rJava’:
 .onLoad failed in loadNamespace() for 'rJava', details:
  call: inDL(x, as.logical(local), as.logical(now), ...)
  error: unable to load shared object 'C:/Users/binis/Documents/R/win-library/3.4/rJava/libs/x64/rJava.dll':
  LoadLibrary failure:  %1 is not a valid Win32 application.

错误与支持我的假设相同。但是,我不明白为什么R会在安装过程中尝试使用不同的Java版本,或者我如何阻止它。我已经测试过INSTALL_opts = c("--no-multiarch", "--no-test-load"), type="source"会做什么,但错误仍然相同......

1 个答案:

答案 0 :(得分:0)

在google / stackoverflow上花了一些时间之后,我发现install_github的语法明显与install.packages略有不同。而不是'INSTALL_opts',用'args'调用选项。因此,以下命令安装示例包而没有“投诉”:

devtools::install_github("ropensci/tabulizer", 
                         args = c("--no-multiarch", "--no-test-load"))

我把它留在这里以防其他人遇到同样的问题。