简体   繁体   English

R:rJava 包安装失败

[英]R: rJava package install failing

When installing rJava using the install.packages("rJava") command I get the following error:使用install.packages("rJava")命令安装 rJava 时,出现以下错误:

checking Java support in R... present:
interpreter : '/usr/bin/java'
archiver    : '/usr/bin/jar'
compiler    : '/usr/bin/javac'
header prep.: '/usr/bin/javah'
cpp flags   : '-I/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../include -I/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../include/linux'
java libs   : '-L/usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/amd64/server -L/usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/amd64 -L/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../lib/amd64 -L -L/usr/java/packages/lib/amd64 -L/usr/lib64 -L/lib64 -L/lib -L/usr/lib -ljvm'
checking whether JNI programs can be compiled... yes
checking JNI data types... configure: error: One or more JNI types differ from the corresponding native type. You may need to use non-standard compiler flags or a different compiler in order to fix this.
ERROR: configuration failed for package ‘rJava’

I have the Java JDK installed and java -version returns the following:我安装了 Java JDK 并且java -version返回以下内容:

$ java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)

When Googling around for the error I see that others are having the same issue but not finding a solution other than "install the whole JDK, not just the JRE" which I have done.当谷歌搜索错误时,我发现其他人也有同样的问题,但除了我已经完成的“安装整个 JDK,而不仅仅是 JRE”之外,没有找到解决方案。

The other thing I read was to run sudo R CMD javareconf which runs quite happily with no errors.我读到的另一件事是运行sudo R CMD javareconf ,它运行得很愉快,没有错误。

Any ideas what my problem is?任何想法我的问题是什么?

[[EDIT]] It's been a few months since I had this problem. [[编辑]]我已经有几个月没有遇到这个问题了。 I had initially solved this by editing my Java paths, as illustrated in the answer I posted below.我最初通过编辑我的 Java 路径解决了这个问题,如我在下面发布的答案中所示。 I recently ran into the same issue on a new Ubuntu install.我最近在新的 Ubuntu 安装中遇到了同样的问题。 I tried Dirk's recommendation to use apt-get to install the rJava package.我尝试了 Dirk 的建议,使用 apt-get 来安装 rJava 包。 It worked perfectly.它工作得很好。 What I failed to appreciate initially is that installing packages using the Ubuntu apt-get method is fundamentally different than just loading the same package using install.packages() inside of R. The Ubuntu packages solve some issues which I didn't realize or appreciate.我最初没有意识到的是,使用 Ubuntu apt-get 方法安装软件包与仅使用 R 中的 install.packages() 加载相同的软件包有着根本的不同。 Ubuntu 软件包解决了一些我没有意识到或没有意识到的问题.

Wouldn't不会

apt-get install r-cran-rjava

have been easier?更容易了? You could have asked me at useR!你可以在useR 上问我 :) :)

Turns out my problem was an issue with my JAVA_HOME environment variable.原来我的问题是我的JAVA_HOME环境变量的问题。 Yes, shocking I know.是的,我知道令人震惊。 My initial setting for PATH and JAVA_HOME looked like this:我对PATHJAVA_HOME初始设置如下所示:

export JAVA_HOME=/usr/lib/jvm/java-6-sun
export PATH=$PATH:$JAVA_HOME/bin

And I added /jre so it now looks like this:我添加了/jre所以它现在看起来像这样:

export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre
export PATH=$PATH:$JAVA_HOME/bin

Everything in Java seemed to work fine without the /jre but rJava would not.如果没有/jre ,Java 中的一切似乎都可以正常工作,但 rJava 则不行。 Odd.奇怪的。

That is how I make it work :这就是我让它工作的方式:

In Linux (Ubuntu 16.04 and 20.04 worked confirmed)在 Linux 中(Ubuntu 16.04 和 20.04 工作确认)

sudo apt-get install default-jre
sudo apt-get install default-jdk
sudo R CMD javareconf

in R:在 R:

install.packages("rJava")

Thanks - your suggestion about $JAVA_HOME lead me to a similar solution:谢谢 - 您对$JAVA_HOME的建议使我找到了类似的解决方案:

unset JAVA_HOME

before invoking R.在调用 R 之前。

I came across the same issue, and it worked after running commands below.我遇到了同样的问题,它在运行下面的命令后工作。

export JAVA_LIBS="$JAVA_LIBS -ldl"
R CMD javareconf

See details at http://www-01.ibm.com/support/knowledgecenter/SSPT3X_3.0.0/com.ibm.swg.im.infosphere.biginsights.install.doc/doc/install_install_r.html请参阅http://www-01.ibm.com/support/knowledgecenter/SSPT3X_3.0.0/com.ibm.swg.im.infosphere.biginsights.install.doc/doc/install_install_r.html 上的详细信息

This worked for me on Ubuntu 12.04 and R version 3.0这在 Ubuntu 12.04 和 R 3.0 版上对我有用

cd /usr/lib/jvm/java-6-sun-1.6.0.26/include

this is the directory that has jni.h这是包含 jni.h 的目录

Next create a soft link to another required header file (I'm too lazy to find out how to include more than one directory in the JAVA_CPPFLAGS option below):接下来创建指向另一个所需头文件的软链接(我懒得找出如何在下面的 JAVA_CPPFLAGS 选项中包含多个目录):

sudo ln -s linux/jni_md.h .

Finally最后

sudo R CMD javareconf JAVA_CPPFLAGS=-I/usr/lib/jvm/java-6-sun-1.6.0.26/include

below is one of my answers on another post - error: unable to load installed packages just now以下是我在另一篇文章中的回答之一 - 错误:现在无法加载已安装的软件包
(this is also relevant to this question) (这也与这个问题有关)

For Linux(Ubuntu) users: If you have oracle-java (7/8) installed.对于 Linux(Ubuntu) 用户:如果您安装了oracle-java (7/8) It'll be at this location /usr/lib/jvm and sudo access is required.它将在此位置/usr/lib/jvm并且需要sudo访问权限。

Create the file /etc/ld.so.conf.d/java.conf with the following entries:使用以下条目创建文件/etc/ld.so.conf.d/java.conf

/usr/lib/jvm/java-8-oracle/jre/lib/amd64
/usr/lib/jvm/java-8-oracle/jre/lib/amd64/server

(Replace java-8-oracle with java-7-oracle depending on your java version) (根据您的 Java 版本将 java-8-oracle 替换为 java-7-oracle)

Then:然后:

sudo ldconfig

Restart RStudio and then install the rJava package.重新启动 RStudio,然后安装 rJava 包。

Running R under Gentoo on an AMD64.在 AMD64 上在 Gentoo 下运行 R。 I upgraded to R 2.12.0我升级到 R 2.12.0

R version 2.12.0 (2010-10-15) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-pc-linux-gnu (64-bit) and those pesky messages went away. R 版本 2.12.0 (2010-10-15) 版权所有 (C) 2010 统计计算 R 基金会 ISBN 3-900051-07-0 平台:x86_64-pc-linux-gnu(64 位)和那些讨厌的消息离开。

Jan Vandermeer扬·范德米尔

I tried to install openjdk-7-* but still I had problems installing rJava.我尝试安装 openjdk-7-* 但仍然在安装 rJava 时遇到问题。 Turns out after I restarted my computer, then there was no problem at all.结果我重新启动计算机后,就完全没有问题了。

so所以

sudo apt-get install openjdk-7-*


RESTART after installing java, then try to install package "rJava" in R

The rJava package looks for the /usr/lib/jvm/default-java/ folder. rJava 包查找/usr/lib/jvm/default-java/文件夹。 But it's not available as default.但它不是默认可用的。 This folder have a symlink for the default java configured for the system.此文件夹具有为系统配置的默认 java 的符号链接。

To activate the default java install the following packages:要激活默认 java 安装以下软件包:

sudo apt-get install default-jre default-jre-headless

Tested on ubuntu 17.04 with CRAN R 3.4.1在带有 CRAN R 3.4.1 的 ubuntu 17.04 上测试

What worked for me was changing JAVA_HOME from file /usr/lib/R/etc/javaconf对我/usr/lib/R/etc/javaconf是从文件/usr/lib/R/etc/javaconf更改 JAVA_HOME

I first checked what was my version of Java enabled : sudo update-alternatives --config java .我首先检查了我启用的 Java 版本: sudo update-alternatives --config java In my case, it was java-8-oracle就我而言,它是java-8-oracle

I opened the file /usr/lib/R/etc/javaconf and replaced default-java by java-8-oracle :我打开了文件/usr/lib/R/etc/javaconf并用java-8-oracle替换了default-java

${JAVA_HOME=/usr/lib/jvm/default-java}

replaced by :取而代之 :

${JAVA_HOME=/usr/lib/jvm/java-8-oracle}

And then sudo R CMD javareconf然后sudo R CMD javareconf

I restarted RStudio, and could then install rJava.我重新启动了 RStudio,然后可以安装 rJava。

what I do is here:我在这里做的是:

  1. in /etc/apt/sources.list, add:在 /etc/apt/sources.list 中,添加:

    deb http://ftp.de.debian.org/debian sid main deb http://ftp.de.debian.org/debian sid main

Note:the rjava should be latest version注意:rjava 应该是最新版本

2 run: sudo apt-get update sudo apt-get install r-cran-rjava 2 运行: sudo apt-get update sudo apt-get install r-cran-rjava

Once update the old version of rjava, then can install rhdfs_1.0.8.一旦更新了旧版本的rjava,就可以安装rhdfs_1.0.8。

我通过下载使其工作: https ://cran.r-project.org/src/contrib/rJava_0.9-8.tar.gz 并运行命令 R CMD install rJava_0.9-8.tar.gz

I was facing the same problem while using Windows 10. I have solved the problem using the following procedure我在使用 Windows 10 时遇到了同样的问题。我已经使用以下过程解决了这个问题

  1. Download Java from https://java.com/en/download/windows-64bit.jsp for 64-bit windows\\Install ithttps://java.com/en/download/windows-64bit.jsp下载 Java for 64-bit windows\\Install it
  2. Download Java development kit from https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html for 64-bit windows\\Install ithttps://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html下载 Java 开发工具包,用于 64 位 Windows\\安装它
  3. Then right click on “This PC” icon in desktop\\Properties\\Advanced system settings\\Advanced\\Environment Variables\\Under System variables select Path\\Click Edit\\Click on New\\Copy and paste paths “C:\\Program Files\\Java\\jdk1.8.0_201\\bin” and “C:\\Program Files\\Java\\jre1.8.0_201\\bin” (without quote) \\OK\\OK\\OK然后右键单击桌面\\属性\\高级系统设置\\高级\\环境变量\\在系统变量下选择路径\\单击编辑\\单击新建\\复制并粘贴路径“C:\\Program Files\\Java\\jdk1”中的“This PC”图标.8.0_201\\bin”和“C:\\Program Files\\Java\\jre1.8.0_201\\bin”(不带引号)\\OK\\OK\\OK

Note : jdk1.8.0_201 and jre1.8.0_201 will be changed depending on the version of Java development kit and Java注意:jdk1.8.0_201 和 jre1.8.0_201 会根据 Java 开发包和 Java 的版本而改变

  1. In Environment Variables window go to User variables for User\\Click on New\\Put Variable name as “JAVA_HOME” and Variable value as “C:\\Program Files\\Java\\jdk1.8.0_201\\bin”\\Press OK在 Environment Variables 窗口中,转到 User variables for User\\单击 New\\Put Variable name as “JAVA_HOME”和变量值作为 “C:\\Program Files\\Java\\jdk1.8.0_201\\bin”\\Press OK

To check the installation, open CMD\\Type javac\\Press Enter and Type java\\press enter It will show要检查安装,请打开 CMD\\Type javac\\Press Enter 并键入 java\\press enter 它将显示在此处输入图片说明

In RStudio run在 RStudio 中运行

Sys.setenv(JAVA_HOME="C:\\Program Files\\Java\\jdk1.8.0_201")

Note : jdk1.8.0_201 will be changed depending on the version of Java development kit注意:jdk1.8.0_201会根据Java开发包的版本而变化

Now you can install and load rJava package without any problem.现在您可以毫无问题地安装和加载 rJava 包。

The problem was rJava wont install in RStudio ( Version 1.0.136 ).问题是 rJava 不会安装在RStudioVersion 1.0.136 )中。 The following worked for me ( macOS Sierra version 10.12.6 ) (found here ):以下对我macOS Sierra version 10.12.6macOS Sierra version 10.12.6 )(在这里找到):

Step-1: Download and install javaforosx.dmg from here步骤 1:从这里下载并安装javaforosx.dmg

Step-2: Next, run the command from inside RStudio:步骤 2:接下来,从 RStudio 内部运行命令:

install.packages("rJava", type = 'source')

On Arch Linux, I needed to install openjdk-src to get a JNI path working.在 Arch Linux 上,我需要安装openjdk-src才能使 JNI 路径正常工作。

In other words, these are the packages I needed to install before sudo R CMD javareconf ran successfully:换句话说,这些是我在sudo R CMD javareconf成功运行之前需要安装的包:

local/jdk-openjdk 14.0.2.u12-1
    OpenJDK Java 14 development kit
local/jre-openjdk 14.0.2.u12-1
    OpenJDK Java 14 full runtime environment
local/jre-openjdk-headless 14.0.2.u12-1
    OpenJDK Java 14 headless runtime environment
local/openjdk-src 14.0.2.u12-1
    OpenJDK Java 14 sources

Assuming you have sudo privileges and not in Ubuntu where package manager makes this easier -- I tried variations of prior answers and found this gem on Databricks blog for nonUbuntu ( https://kb.databricks.com/r/install-rjava-rjdbc-libraries.html )假设你有 sudo 权限,而不是在包管理器使这更容易的 Ubuntu 中——我尝试了先前答案的变体,并在非 Ubuntu 的 Databricks 博客上找到了这个 gem ( https://kb.databricks.com/r/install-rjava-rjdbc -libraries.html )

  1. Installed JDK安装的JDK
sudo apt-get install openjdk-8-jdk
  1. Verify path to libjvm.so;验证 libjvm.so 的路径; for me-->
cd /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64 
grep -r libjvm

output:输出:

Binary file server/libjvm.so matches <<<<<<<<
  1. Do java configure做java配置
    sudo R CMD javareconf
  1. Remove prior versions of the package and install 'rJava' from CRAN mirror in RStudio删除先前版本的软件包并从 RStudio 的 CRAN 镜像中安装“rJava”

  2. Restart RStudio重启 RStudio

  3. In RStudio verify link to libjvm.so在 RStudio 中验证指向 libjvm.so 的链接

    dyn.load('/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so')
    library('rJava')

I've encountered similar problem on Ubuntu 16.04 and was able to solve it by creating a folder named "default-java" in /usr/lib/jvm and copying into it all the contents of the /usr/lib/jvm/java-8-oracle .我遇到在Ubuntu 16.04类似的问题,并能够通过创建一个名为“默认Java”的文件夹来解决它/usr/lib/jvm ,并复制到它的所有内容的/usr/lib/jvm/java-8-oracle I opted for this solution as correcting JAVA_HOME environment variable turned out to be of no use.我选择了这个解决方案,因为纠正 JAVA_HOME 环境变量没有用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM