R:rJava 软件包安装失败

发布于 2024-09-11 04:25:26 字数 1536 浏览 6 评论 0 原文

使用 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’

我安装了 Java JDK,并且 java -version 返回以下内容:

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

当 Google 搜索时对于该错误,我发现其他人也有同样的问题,但除了我所做的“安装整个 JDK,而不仅仅是 JRE”之外,没有找到解决方案。

我读到的另一件事是运行 sudo R CMD javareconf ,它运行得非常愉快,没有错误。

有什么想法我的问题是什么吗?

[[编辑]] 我遇到这个问题已经几个月了。我最初通过编辑 Java 路径解决了这个问题,如我下面发布的答案所示。我最近在新安装的 Ubuntu 上遇到了同样的问题。我尝试了 Dirk 的建议,使用 apt-get 安装 rJava 包。效果非常好。我最初没有意识到的是,使用 Ubuntu apt-get 方法安装软件包与仅使用 R 内部的 install.packages() 加载相同的软件包有本质上的不同。Ubuntu 软件包解决了一些我没有意识到或欣赏的问题。

When installing rJava using the install.packages("rJava") command I get the following error:

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 -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.

The other thing I read was to run sudo R CMD javareconf which runs quite happily with no errors.

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. I recently ran into the same issue on a new Ubuntu install. I tried Dirk's recommendation to use apt-get to install the rJava package. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(18

左耳近心 2024-09-18 04:25:28

我所做的在这里:

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

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

注意:rjava 应该是最新版本

2 运行:
sudo apt-get 更新
sudo apt-get install r-cran-rjava

一旦更新了旧版本的rjava,就可以安装rhdfs_1.0.8。

what I do is here:

  1. in /etc/apt/sources.list, add:

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

Note:the rjava should be latest version

2 run:
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.

吖咩 2024-09-18 04:25:28

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

I got it working by downloading : https://cran.r-project.org/src/contrib/rJava_0.9-8.tar.gz and running command R CMD install rJava_0.9-8.tar.gz

予囚 2024-09-18 04:25:28

我在使用 Windows 10 时遇到了同样的问题。我已经使用以下过程解决了该问题:

  1. https://java.com/en/download/windows-64bit.jsp(适用于 64 位 Windows)\安装
  2. https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 对于 64 位 Windows\安装它
  3. 然后右键单击桌面\属性\高级系统设置\高级\环境变量\在系统变量下选择路径\单击编辑\单击新建\复制中的“此电脑”图标粘贴路径“C:\Program Files\Java\jdk1.8.0_201\bin”和“C:\Program Files\Java\jre1.8.0_201\bin”(不带引号)\OK\OK\OK

注意< /strong>:jdk1.8.0_201和jre1.8.0_201将根据Java开发套件和Java的版本而改变

  1. 在环境变量窗口中转到用户的用户变量\单击新建\将变量名称设置为“JAVA_HOME”和变量值为“C:\Program Files\Java\jdk1.8.0_201\bin”\按 OK

要检查安装,请打开 CMD\键入 javac\按 Enter 并
输入java\按回车键
它将显示 在此处输入图像描述

在RStudio中运行

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

注意:jdk1.8.0_201将根据Java开发套件的版本而变化

现在您可以毫无问题地安装和加载rJava包。

I was facing the same problem while using Windows 10. I have solved the problem using the following procedure

  1. Download Java from https://java.com/en/download/windows-64bit.jsp 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 it
  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

Note: jdk1.8.0_201 and jre1.8.0_201 will be changed depending on the version of Java development kit and 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

To check the installation, open CMD\Type javac\Press Enter and
Type java\press enter
It will show enter image description here

In RStudio run

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

Now you can install and load rJava package without any problem.

马蹄踏│碎落叶 2024-09-18 04:25:28

在 Arch Linux 上,我需要安装 openjdk-src 才能使 JNI 路径正常工作。

换句话说,这些是我在成功运行 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

On Arch Linux, I needed to install openjdk-src to get a JNI path working.

In other words, these are the packages I needed to install before sudo R CMD javareconf ran successfully:

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
无戏配角 2024-09-18 04:25:28

问题是 rJava 无法安装在 RStudio版本 1.0.136)中。以下内容对我有用(macOS Sierra 版本 10.12.6)(在 此处< /a>):

第 1 步:从 此处

步骤 2:接下来,从 RStudio 内部运行命令:

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

The problem was rJava wont install in RStudio (Version 1.0.136). The following worked for me (macOS Sierra version 10.12.6) (found here):

Step-1: Download and install javaforosx.dmg from here

Step-2: Next, run the command from inside RStudio:

install.packages("rJava", type = 'source')
書生途 2024-09-18 04:25:28

假设你有 sudo 权限,而不是在 Ubuntu 中,包管理器使这变得更容易——我尝试了先前答案的变体,并在非 Ubuntu 的 Databricks 博客上找到了这个 gem (https://kb.databricks.com/r/install-rjava-rjdbc-libraries.html)

  1. 安装的 JDK
sudo apt-get install openjdk-8-jdk
  1. 验证 libjvm 的路径。所以; 对我来说 -->
cd /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64 
grep -r libjvm

输出:

Binary file server/libjvm.so matches <<<<<<<<
  1. 执行 java 配置
    sudo R CMD javareconf
  1. 删除软件包的早期版本并从 RStudio 中的 CRAN 镜像安装“rJava”

  2. 重新启动 RStudio

  3. 在 RStudio 中验证 libjvm.so 的链接

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

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)

  1. Installed JDK
sudo apt-get install openjdk-8-jdk
  1. Verify path to 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
    sudo R CMD javareconf
  1. Remove prior versions of the package and install 'rJava' from CRAN mirror in RStudio

  2. Restart RStudio

  3. In RStudio verify link to libjvm.so

    dyn.load('/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so')
    library('rJava')
随心而道 2024-09-18 04:25:28

我在 Ubuntu 16.04 上遇到了类似的问题,并且能够通过在 /usr/lib/jvm 中创建一个名为“default-java”的文件夹并将 的所有内容复制到其中来解决该问题>/usr/lib/jvm/java-8-oracle。我选择了这个解决方案,因为纠正 JAVA_HOME 环境变量结果是没有用的。

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. I opted for this solution as correcting JAVA_HOME environment variable turned out to be of no use.

執念 2024-09-18 04:25:27

这就是我让它工作的方式:

在 Linux 中(Ubuntu 16.04 和 20.04 已确认工作)

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

在 R 中:

install.packages("rJava")

That is how I make it work :

In Linux (Ubuntu 16.04 and 20.04 worked confirmed)

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

in R:

install.packages("rJava")
千鲤 2024-09-18 04:25:27

谢谢 - 您关于 $JAVA_HOME 的建议引导我找到了类似的解决方案:

unset JAVA_HOME

在调用 R 之前。

Thanks - your suggestion about $JAVA_HOME lead me to a similar solution:

unset JAVA_HOME

before invoking R.

北笙凉宸 2024-09-18 04:25:27

我遇到了同样的问题,运行下面的命令后它就起作用了。

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

详情请参阅
http://www-01.ibm.com/support/knowledgecenter/SSPT3X_3.0.0/com.ibm.swg.im.infosphere.biginsights.install.doc/doc/install_install_r.html

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

你在看孤独的风景 2024-09-18 04:25:27

这在 Ubuntu 12.04 和 R 版本 3.0 上对我有用

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

这是具有 jni.h 的目录

接下来创建到另一个所需头文件的软链接(我懒得找出如何在 JAVA_CPPFLAGS 选项中包含多个目录下):

sudo ln -s linux/jni_md.h .

最后

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

This worked for me on Ubuntu 12.04 and R version 3.0

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

this is the directory that has 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):

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
小瓶盖 2024-09-18 04:25:27

以下是我在另一篇文章中的答案 - 错误:无法加载刚才安装的包
(这也与这个问题相关)

对于Linux(Ubuntu)用户:如果您有 oracle-java (7/8) 已安装。它将位于 /usr/lib/jvm 位置,并且需要 sudo 访问权限。

使用以下条目创建文件 /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

根据您的 java 版本,将 java-8-oracle 替换为 java-7-oracle)

然后:

sudo ldconfig

重新启动 RStudio,然后安装 rJava 包。

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. It'll be at this location /usr/lib/jvm and sudo access is required.

Create the file /etc/ld.so.conf.d/java.conf with the following entries:

/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)

Then:

sudo ldconfig

Restart RStudio and then install the rJava package.

箹锭⒈辈孓 2024-09-18 04:25:27

在 AMD64 上的 Gentoo 下运行 R。我升级到R 2.12.0

R版本2.12.0 (2010-10-15)
版权所有 (C) 2010 R 统计计算基金会
ISBN 3-900051-07-0
平台:x86_64-pc-linux-gnu(64位)
那些烦人的信息就消失了。

简·范德米尔

Running R under Gentoo on an AMD64. I upgraded to 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.

Jan Vandermeer

爱殇璃 2024-09-18 04:25:27

我尝试安装 openjdk-7-* 但在安装 rJava 时仍然遇到问题。结果我重新启动电脑后就没有任何问题了。

所以

sudo apt-get install openjdk-7-*


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

I tried to install openjdk-7-* but still I had problems installing 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
小嗲 2024-09-18 04:25:27

rJava 包查找 /usr/lib/jvm/default-java/ 文件夹。但默认情况下它不可用。该文件夹有一个为系统配置的默认 java 的符号链接。

要激活默认的 java,请安装以下软件包:

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

在 ubuntu 17.04 上使用 CRAN R 3.4.1 进行测试

The rJava package looks for the /usr/lib/jvm/default-java/ folder. But it's not available as default. This folder have a symlink for the default java configured for the system.

To activate the default java install the following packages:

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

Tested on ubuntu 17.04 with CRAN R 3.4.1

两相知 2024-09-18 04:25:27

对我有用的是从文件 /usr/lib/R/etc/javaconf 更改 JAVA_HOME

我首先检查了我启用的 Java 版本:sudo update-alternatives --config java.
就我而言,它是 java-8-oracle

我打开文件 /usr/lib/R/etc/javaconf 并替换 default-java > 由 java-8-oracle

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

替换为:

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

然后 sudo R CMD javareconf

我重新启动了 RStudio,然后可以安装 rJava。

What worked for me was changing JAVA_HOME from file /usr/lib/R/etc/javaconf

I first checked what was my version of Java enabled : sudo update-alternatives --config java.
In my case, it was java-8-oracle

I opened the file /usr/lib/R/etc/javaconf and replaced default-java by java-8-oracle :

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

replaced by :

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

And then sudo R CMD javareconf

I restarted RStudio, and could then install rJava.

绮筵 2024-09-18 04:25:26

不是

apt-get install r-cran-rjava

更容易吗?您可以在 useR! 上问我:)

Wouldn't

apt-get install r-cran-rjava

have been easier? You could have asked me at useR! :)

无名指的心愿 2024-09-18 04:25:26

原来我的问题是我的 JAVA_HOME 环境变量的问题。是的,我知道令人震惊。我对 PATHJAVA_HOME 的初始设置如下所示:

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

我添加了 /jre 所以它现在看起来像这样:

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

Java 中的一切似乎都可以工作没有 /jre 没问题,但 rJava 就不行。奇怪的。

Turns out my problem was an issue with my JAVA_HOME environment variable. Yes, shocking I know. My initial setting for PATH and JAVA_HOME looked like this:

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:

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. Odd.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文