简体   繁体   English

安装包时,.onLoad在'rJava'的loadNamespace()中失败

[英].onLoad failed in loadNamespace() for 'rJava' when installing a package

I have a package "javaOnLoadFailed" (just a minimal package for testing my issue, hence the weird name) which imports rJava. 我有一个包“javaOnLoadFailed”(只是用于测试我的问题的最小包,因此是奇怪的名称),它导入了rJava。 I get 'rJava' errors when I try to either check() or install() the package, even though require(rJava) itself works fine. 当我尝试检查()或安装()包时,我得到'rJava'错误,即使require(rJava)本身工作正常。

install() gives the following errors: install()给出以下错误:

> install()
Installing javaOnloadFailed
"C:/Program Files/R/R-3.2.0/bin/x64/R" --no-site-file --no-environ --no-save  \
--no-restore CMD INSTALL  \
"C:/Projects/stackoverflow/javaOnloadFailed/javaOnLoadFailed"  \
--library="C:/Users/adb2018/Documents/R/win-library/3.2" --with-keep.source  \
--install-tests 

* installing *source* package 'javaOnloadFailed' ...
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: inDL(x, as.logical(local), as.logical(now), ...)
  error: unable to load shared object 'C:/Users/adb2018/Documents/R/win-library/3.2/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/adb2018/Documents/R/win-library/3.2/javaOnloadFailed'
Error: Command failed (1)

I am using R 3.2.0 from within Architect, with sessionInfo(): 我在Architect中使用R 3.2.0,使用sessionInfo():

R version 3.2.0 (2015-04-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] devtools_1.7.0.9000 rj_2.0.3-2         

loaded via a namespace (and not attached):
[1] tools_3.2.0   rj.gd_2.0.0-1

The Java environment variable is empty Java环境变量为空

> Sys.getenv('JAVA')
[1] ""

Based on a suggestion , I tried setting the JAVA environment variable to point to the 64 Bit version of Java (because I am running R 64 bit, as you could see from the sessionInfo, but that doesn't work: 基于一个建议 ,我尝试将JAVA环境变量设置为指向64位版本的Java(因为我正在运行R 64位,正如您从sessionInfo中看到的那样,但这不起作用:

> Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre1.8.0_45')
> install()
Installing javaOnloadFailed
"C:/Program Files/R/R-3.2.0/bin/x64/R" --no-site-file --no-environ --no-save  \
  --no-restore CMD INSTALL  \
  "C:/Projects/stackoverflow/javaOnloadFailed/javaOnLoadFailed"  \
  --library="C:/Users/adb2018/Documents/R/win-library/3.2" --with-keep.source  \
  --install-tests 

* installing *source* package 'javaOnloadFailed' ...
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: inDL(x, as.logical(local), as.logical(now), ...)
  error: unable to load shared object 'C:/Users/adb2018/Documents/R/win-library/3.2/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/adb2018/Documents/R/win-library/3.2/javaOnloadFailed'
Error: Command failed (1)

I then tried to set the JAVA environment variable such that it points to the 32 bit version of Java on my system, and then it works! 然后我尝试设置JAVA环境变量,使其指向我系统上的32位版本的Java,然后它就可以了!

> Sys.setenv(JAVA_HOME='C:\\Program Files (x86)\\Java\\jre1.8.0_45\\')
> install()
Installing javaOnloadFailed
"C:/Program Files/R/R-3.2.0/bin/x64/R" --no-site-file --no-environ --no-save  \
  --no-restore CMD INSTALL  \
  "C:/Projects/stackoverflow/javaOnloadFailed/javaOnLoadFailed"  \
  --library="C:/Users/adb2018/Documents/R/win-library/3.2" --with-keep.source  \
  --install-tests 

* installing *source* package 'javaOnloadFailed' ...
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
*** arch - x64
* DONE (javaOnloadFailed)

[INFO] Updating the R environment index started...

[INFO] The R environment index was updated successfully.

I don't quite understand why I need to point to Java 32 bit to make R 64 bit work, but that's what seems to be the case. 我不太明白为什么我需要指向Java 32位来使R 64位工作,但这似乎就是这种情况。

By the way, don't stumble over my package name "javaOnLoadFailed". 顺便说一句,不要偶然发现我的包名“javaOnLoadFailed”。 I just created a minimal package with that name to test the problem. 我刚刚创建了一个带有该名称的最小包来测试问题。

Many packages fail install because they are not meant to run on i386 platform but the standard installation process tries to do that. 许多软件包因安装失败而无法在i386平台上运行,但标准安装过程会尝试这样做。 Users waste a lot of time with jvm.dll and PATH and JAVA_HOME when the real fix is to force the installed to just forget about i386. 用户在jvm.dll和PATH以及JAVA_HOME上浪费了大量时间,当真正的修复是强制安装时忘记i386。 Use option for install.packages. 使用install.packages选项。 (this also works when drat library is used. (credit goes to Dason) (这在使用drat库时也有效。(信用到Dason)

install.packages("SqlRender",INSTALL_opts="--no-multiarch")

Remember the problem is that R doesn't know where jvm.dll is. 记住问题是R不知道jvm.dll在哪里。 When you set JAVA_HOME use the path of the directory that contains the dll file. 设置JAVA_HOME时,请使用包含dll文件的目录的路径。 You can find it in bin\\client or bin\\server . 您可以在bin\\clientbin\\server找到它。 The command then becomes: 然后该命令变为:

Sys.setenv(JAVA_HOME='C:\\\\Program Files\\\\Java\\\\jre1.8.0_45\\\\bin\\\\client')

I tried remove the JAVA_HOME system variable and it works. 我尝试删除JAVA_HOME系统变量,它的工作原理。 So that when you launch R, Sys.getenv("JAVA_HOME") gives you "" . 因此,当您启动R时, Sys.getenv("JAVA_HOME")会为您提供""

I have found the same problem when trying to install a package only available in Github. 我在尝试安装仅在Github中可用的软件包时发现了同样的问题。
This solved for me: 这解决了我:

devtools::install_github("snowflakedb/dplyr-snowflakedb", INSTALL_opts=c("--no-multiarch"))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:.onLoad在'rJava'的loadNamespace()中失败,详细信息在安装软件包时 - Error : .onLoad failed in loadNamespace() for 'rJava', details while installing a package R - 错误:'rJava' 的 loadNamespace() 中的 .onLoad 失败 - R - Error : .onLoad failed in loadNamespace() for 'rJava' 错误:“ geoR”的程序包或名称空间加载失败:.tcltk的loadNamespace()在.onLoad中失败 - Error: package or namespace load failed for ‘geoR’: .onLoad failed in loadNamespace() for 'tcltk' 错误:'rJava' 的 loadNamespace() 中的 .onLoad 失败,详细信息:调用:inDL(x, as.logical(local), as.logical(now), ...) - Error : .onLoad failed in loadNamespace() for 'rJava', details: call: inDL(x, as.logical(local), as.logical(now), …) 错误“.onLoad 在 'tcltk' 的 loadNamespace() 中失败” - Error ".onLoad failed in loadNamespace() for 'tcltk'" 'utils' 的 loadNamespace() 中的 onLoad 失败,详细信息 - onLoad failed in loadNamespace() for 'utils', details 安装rJava软件包时出现配置错误 - configuration error when installing rJava package 安装 package 时,是否有针对 R 给出错误消息“加载命名空间错误”的解决方案? - Is there a solution for R giving an error message "error in loadnamespace" when installing a package? 使用 Docker 安装 rJava 包 - Installing rJava package with Docker 安装 rJava package 的问题 - Problems with installing rJava package
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM