我在Linux服务器RHEL6上工作,我安装了anaconda。我有以下设置
conda-env version : 4.3.13
conda-build version : 2.1.4
python version : 2.7.13.final.0
rpy2 : 2.8.5
我安装了rpy2以在python中使用R.但是随着用conda安装的R版本我有问题安装" rJava"。
checking whether Java run-time works... yes
checking whether -Xrs is supported... yes
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'
我在同一台机器上安装了我的独立版本的R,我没有问题,所以我知道我安装了正确的版本。
对于我使用相同R版本的2种不同设置(带有con的R的独立R),我有相同的Java版本
java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
对于这两种设置,以下变量不会退出
R_JAVA_LD_LIBRARY_PATH
JAVA_HOME
定义。 PATH与独立版非常相似:
PATH=/opt/ccda/anaconda2/bin:/opt/opennlp/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
对于安装了conda的R,我有:
PATH=/opt/ccda/anaconda2/envs/py27CCA/bin:/opt/ccda/anaconda2/bin:/opt/ccda/anaconda2/bin:/opt/opennlp/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
这里是编译期间的信息。对于独立的R版本:
interpreter : '/usr/bin/java'
archiver : '/usr/bin/jar'
compiler : '/usr/bin/javac'
header prep.: '/usr/bin/javah'
cpp flags : '-I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include/linux'
java libs : '-L/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/amd64/server -ljvm
对于使用conda安装的R版本:
interpreter : '/usr/lib/jvm/java/jre/bin/java'
archiver : '/usr/lib/jvm/java/jre/../bin/jar'
compiler : '/usr/lib/jvm/java/jre/../bin/javac'
header prep.: '/usr/lib/jvm/java/jre/../bin/javah'
cpp flags : '-I/usr/lib/jvm/java/include -I/usr/lib/jvm/java/include/linux'
java libs : '-L/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/amd64/server -ljvm'
我尝试使用相同的路径:
export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java
export R_JAVA_LD_LIBRARY_PATH=${JAVA_HOME}/lib/amd64/server
export JAVA_CPPFLAGS="-I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include/linux"
顺便说一下:
/usr/bin/java -> /etc/alternatives/java
/etc/alternatives/java -> /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java
但重新运行后:
R CMD javareconf
并重新编译我得到相同的错误,而路径现在看起来一样:
interpreter : '/usr/bin/java'
archiver : '/usr/bin/jar'
compiler : '/usr/bin/javac'
header prep.: '/usr/bin/javah'
cpp flags : '-I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include/linux'
java libs : '-L/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/amd64/server -ljvm'
所以我不明白这意味着什么"一个或多个JNI类型不同"我应该在道路和旗帜上让它发挥作用。
R CMD javareconf
Java interpreter : /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java
Java version : 1.8.0_121
Java home path : /usr/lib/jvm/jre-1.8.0-openjdk.x86_64
Java compiler : /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/../bin/javac
Java headers gen.: /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/../bin/javah
Java archive tool: /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/../bin/jar
trying to compile and link a JNI program
detected JNI cpp flags : -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include/linux
detected JNI linker flags : -L/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/amd64/server -ljvm
gcc -std=gnu99 -I/opt/ccda/anaconda2/envs/py27CCA/lib/R/include -DNDEBUG -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include/linux -I/opt/ccda/anaconda2/envs/py27CCA/include -fpic -I/opt/ccda/anaconda2/envs/py27CCA/include -c conftest.c -o conftest.o
gcc -std=gnu99 -shared -L/opt/ccda/anaconda2/envs/py27CCA/lib/R/lib -L/opt/ccda/anaconda2/envs/py27CCA/lib -lgfortran -o conftest.so conftest.o -L/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/amd64/server -ljvm -L/opt/ccda/anaconda2/envs/py27CCA/lib/R/lib -lR
JAVA_HOME : /usr/lib/jvm/jre-1.8.0-openjdk.x86_64
Java library path: /usr/lib/jvm/java/jre/lib/amd64/server
JNI cpp flags : -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include -I/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/../include/linux
JNI linker flags : -L/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el6_8.x86_64/jre/lib/amd64/server -ljvm
Updating Java configuration in /opt/ccda/anaconda2/envs/py27CCA/lib/R
Done.
我不明白,因为我不太了解错误信息的含义。我尝试了与类似问题相关的各种线程的所有建议。
编辑:使用导出
LD_LIBRARY_PATH=$JAVA_HOME/lib/amd64:$JAVA_HOME/lib/amd64/server
解决部分问题(在这种情况下不再需要JAVA_HOME)但我还有其他问题:
在这种情况下不使用-m64标志(当它与独立的R版本一起使用时)
/ usr / bin / ld:找不到-liconv
但是图书馆存在:
/opt/ccda/anaconda2/envs/py27CCA/lib/libiconv.so
/opt/ccda/anaconda2/envs/py27CCA/lib/libiconv.so.2
/opt/ccda/anaconda2/envs/py27CCA/lib/libiconv.so.2.5.1
/opt/ccda/anaconda2/envs/py27CCA/lib/preloadable_libiconv.so
但可能不在使用的路径中,所以我现在需要解决这个问题。
答案 0 :(得分:1)
确保使用指向JDK的显式设置重新配置R环境。
确保JAVA_HOME指向JDK
export JAVA_HOME=your_JDK_installation
然后,重新配置R并明确传递所有位置
sudo R CMD javareconf \
JAVA_HOME=${JAVA_HOME} \
JAVA=${JAVA_HOME/bin/java \
JAVAC=${JAVA_HOME}/bin/javac \
JAVAH=${JAVA_HOME}/bin/javah \
JAR=${JAVA_HOME}/bin/jar \
JAVA_LD_LIBRARY_PATH=${JAVA_HOME}/jre/lib/server \
JAVA_CPPFLAGS="-I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux"
然后,尝试在R
之外配置rJavacurl https://cran.r-project.org/src/contrib/rJava_0.9-8.tar.gz -o rJava_0.9-8.tar.gz
tar zxf rJava_0.9-8.tar.gz
cd rJava
./configure
如果有效,您应该能够从R
中的来源安装它 install.packages("rJava", type="source")