我已经使用Ubuntu 16.04.LTS和RStudio(请参阅下面的sessionInfo()
输出)重新激活我的休眠Amazon EC2微实例(感谢AMI Louis Aslett)。在首先访问AWS实例后,我已经运行sudo apt-get update
。
当我尝试在R Studio中安装一些软件包(例如xlsx和其他软件包)时(由于缺少Java,我发现了一个错误,这似乎是一个常见问题)。我遵循建议1)安装依赖项(例如xlsx
,例如rJava
和xlsxjars
)separately; 2)apt-get install r-cran-rjava
按建议here。然后检查已安装的java -version
显示
openjdk version" 1.8.0_131"
OpenJDK运行时环境(版本1.8.0_131-8u131-b11-0ubuntu1.16.04.2-b11)
OpenJDK 64位服务器VM(内置25.131-b11,混合模式)
提出了类似的问题" rJava load error in RStudio/R after “upgrading” to OSX Yosemite"在这里" error: unable to load installed packages...",其中解决方案似乎是将java的路径链接到R export LD_LIBRARY_PATH=$JAVA_LD_LIBRARY_PATH
或设置R' s env。变量Sys.setenv(JAVA_HOME='/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/server')
。
然而,运行R CMD javareconf -e
显示(我想)一些更深层次的问题(see Image)& /或片段:
R CMD javareconf -e
Java interpreter : /usr/lib/jvm/default-java/jre/bin/java
Java version : 1.8.0_131
Java home path : /usr/lib/jvm/default-java
Java compiler : not present
Java headers gen.:
Java archive tool:
trying to compile and link a JNI program
detected JNI cpp flags :
detected JNI linker flags : -L$(JAVA_HOME)/jre/lib/amd64/server -ljvm
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c conftest.c -o conftest.o
conftest.c:1:17: fatal error: jni.h: No such file or directory
compilation terminated.
/usr/lib/R/etc/Makeconf:132: recipe for target 'conftest.o' failed
make: *** [conftest.o] Error 1
Unable to compile a JNI program
The following Java variables have been exported:
JAVA_HOME JAVA JAVAC JAVAH JAR JAVA_LIBS JAVA_CPPFLAGS JAVA_LD_LIBRARY_PATH
Running: /bin/bash

使用Java编译器:不存在和
conftest.c:1:17:致命错误:jni.h:没有这样的文件或目录 编译终止。 / usr / lib / R / etc / Makeconf:132:目标配方' conftest.o'失败
然后我发现了一个问题" how to make jni.h be found?":这里提出的最佳解决方案gcc -I/usr/lib/jvm/jdk1.7.0_07/include
检查同一目录cd /usr/lib/jvm/
并列出其内容ls --all
显示:
.DEFAULT-java的
的.java-1.8.0-的OpenJDK,amd64.jinfo
..java-1.8.0-的OpenJDK,AMD64 的java -8-的openjdk-AMD64
正在运行,gcc -I/usr/lib/jvm/java-1.8.0-openjdk-amd64/include
导致:gcc: fatal error: no input files
另外,我尝试了sudo apt-get install openjdk-X-jdk
(它是建议的答案之一" how to make jni.h be found?")但可能包不再存在"无法找到包openjdk-X -jdk&#34 ;.
不幸的是,我陷入困境并且没有足够的技能来实现其他(看似更复杂的解决方案)。我真的很感激一些帮助/输入。
R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.1 LTS
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] parallel compiler stats graphics grDevices utils datasets
[8] methods base
other attached packages:
[1] openxlsx_4.0.17 qdapTools_1.3.1 qdapRegex_0.7.2
[4] qdapDictionaries_1.0.6 stringr_1.1.0 stringi_1.1.2
[7] dplyr_0.5.0 tm_0.7-1 NLP_0.1-10
[10] scales_0.4.0 RColorBrewer_1.1-2 ParallelForest_1.1.0
[13] doMC_1.3.4 iterators_1.0.8 foreach_1.4.3
[16] boot_1.3-18 reshape2_1.4.1 glmm_1.1.1
[19] Matrix_1.2-6 mvtnorm_1.0-5 trust_0.1-7
[22] ggplot2_2.1.0 shiny_0.13.2
loaded via a namespace (and not attached):
[1] gtools_3.5.0 slam_0.1-40 lattice_0.20-33
[4] colorspace_1.2-7 htmltools_0.3.5 chron_2.3-50
[7] XML_3.98-1.7 DBI_0.5-1 plyr_1.8.4
[10] munsell_0.4.3 gtable_0.2.0 codetools_0.2-14
[13] httpuv_1.3.3 gender_0.5.1 Rcpp_0.12.7
[16] xtable_1.8-2 gdata_2.17.0 mime_0.5
[19] gridExtra_2.2.1 digest_0.6.10 grid_3.3.1
[22] tools_3.3.1 bitops_1.0-6 magrittr_1.5
[25] RCurl_1.95-4.8 tibble_1.2 data.table_1.10.4
[28] assertthat_0.1 R6_2.2.0 igraph_1.0.1

答案 0 :(得分:1)
您需要安装JDK。看看这里。
我描述了如何使用R,Java和rJava包。即使描述是基于macOS的,它也应该适用于Linux。这是一种非常通用的方法。
您的问题与您使用JRE而不是JDK的事实有关。那里缺少JNI标题。
答案 1 :(得分:0)
我的一位朋友建议使用sudo apt-get install openjdk-8-jdk
在ec2实例上安装java,有趣的是,它解决了这个问题。
答案 2 :(得分:0)
已经晚了两年,但是对我有用的是遵循此链接# Install the Java Runtime Environment (JRE).
sudo apt-get install -y default-jre
# Install the Java Development Kit (JDK).
sudo apt-get install -y default-jdk
# Update where R expects to find various Java files.
sudo R CMD javareconf
# Install the package.
> install.packages("rJava")
上的指示。在评论时,他们是:
function Dropzone(props) {
function getOrientation(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onerror = reject
reader.onload = ({ target }) => {
try {
const view = new DataView(target.result),
length = view.byteLength
let offset = 2
if (view.getUint16(0, false) != 0xFFD8) {
}
while (offset < length) {
const marker = view.getUint16(offset, false)
offset += 2;
if (marker == 0xFFE1) {
if (view.getUint32(offset += 2, false) != 0x45786966) {
return resolve()
}
const little = view.getUint16(offset += 6, false) == 0x4949
offset += view.getUint32(offset + 4, little)
const tags = view.getUint16(offset, little)
offset += 2
for (var i = 0; i < tags; i++) {
if (view.getUint16(offset + (i * 12), little) == 0x0112) {
return resolve(view.getUint16(offset + (i * 12) + 8, little))
}
}
} else if ((marker & 0xFF00) != 0xFF00) {
break;
} else {
offset += view.getUint16(offset, false)
}
}
return resolve()
} catch (err) {
console.log(err)
}
};
reader.readAsArrayBuffer(file.slice(0, 64 * 1024));
})
}
const [thumbs, setThumbs] = useState([]);
const [files, setFiles] = useState([]);
const { getRootProps, getInputProps } = useDropzone({
accept: 'image/*',
onDrop: acceptedFiles => {
let filesCollection = [];
files.map((file) => {
filesCollection.push(file);
});
acceptedFiles.map(file => {
filesCollection.push(
Object.assign(file, {
preview: URL.createObjectURL(file)
})
);
});
setFiles(filesCollection);
props.handleFiles(filesCollection);
}
});
useEffect(() => () => {
// Make sure to revoke the data uris to avoid memory leaks
files.forEach(file => URL.revokeObjectURL(file.preview));
}, [files]);
useEffect(() => {
const fetchData = async () => {
let thumbCollection = [];
files.map(async (file) => {
let orient = await getOrientation(file);
thumbCollection.push((
<div style={thumb} key={file.name}>
<div style={thumbInner}>
<img
src={file.preview}
style={{ ...img, transform: ORIENT_TRANSFORMS[orient] }}
/>
</div>
</div>
));
});
setThumbs(thumbCollection);
}
fetchData();
}, [files]);
useEffect(() => {
eventFire(window, 'click');
}, [thumbs]);
return (
<section className="dropContainer">
<div {...getRootProps({ className: 'dropzone' })}>
<input {...getInputProps()} />
<p style={{ color: "black" }}>Drag 'n' drop some files here, or click to select files</p>
<div className="dropzone-svgContainer">
<UploadImageIcon />
</div>
</div>
<aside style={thumbsContainer}>
{thumbs}
</aside>
</section>
);
}