如何使用 Linux Debian 正确安装 R keras

Posted

技术标签:

【中文标题】如何使用 Linux Debian 正确安装 R keras【英文标题】:How correct install R keras using Linux Debian 【发布时间】:2021-10-25 12:24:15 【问题描述】:

我有虚拟 debian 服务器。即

braingen@vm-mob:~$ Linux vm-mob 4.19.0-9-amd64 #1 SMP Debian 4.19.118-2+deb10u1 (2020-06-07) x86_64

我已经安装了 r-base-core

sudo apt-get install r-base-core
R

在 R 控制台中我尝试安装 keras

install.packages("keras")

当我这样做时,我会遇到麻烦

he downloaded source packages are in
        ‘/tmp/RtmpxmyvE9/downloaded_packages’
Warning messages:
1: In install.packages("keras") :
  installation of package ‘Rcpp’ had non-zero exit status
2: In install.packages("keras") :
  installation of package ‘png’ had non-zero exit status
3: In install.packages("keras") :
  installation of package ‘reticulate’ had non-zero exit status
4: In install.packages("keras") :
  installation of package ‘tfautograph’ had non-zero exit status
5: In install.packages("keras") :
  installation of package ‘tfruns’ had non-zero exit status
6: In install.packages("keras") :
  installation of package ‘tensorflow’ had non-zero exit status
7: In install.packages("keras") :
  installation of package ‘keras’ had non-zero exit status
>

所以我当然不能加载库。

如何正确安装 keras 和依赖项? 谢谢

完整的日志

> install.packages("keras")
Installing package into ‘/home/braingen/R/x86_64-pc-linux-gnu-library/3.5’
(as ‘lib’ is unspecified)
also installing the dependencies ‘Rcpp’, ‘png’, ‘tfautograph’, ‘reticulate’, ‘tensorflow’, ‘tfruns’

trying URL 'https://cloud.r-project.org/src/contrib/Rcpp_1.0.7.tar.gz'
Content type 'application/x-gzip' length 2941808 bytes (2.8 MB)
==================================================
downloaded 2.8 MB

trying URL 'https://cloud.r-project.org/src/contrib/png_0.1-7.tar.gz'
Content type 'application/x-gzip' length 24990 bytes (24 KB)
==================================================
downloaded 24 KB

trying URL 'https://cloud.r-project.org/src/contrib/tfautograph_0.3.1.tar.gz'
Content type 'application/x-gzip' length 46883 bytes (45 KB)
==================================================
downloaded 45 KB

trying URL 'https://cloud.r-project.org/src/contrib/reticulate_1.20.tar.gz'
Content type 'application/x-gzip' length 832951 bytes (813 KB)
==================================================
downloaded 813 KB

trying URL 'https://cloud.r-project.org/src/contrib/tensorflow_2.6.0.tar.gz'
Content type 'application/x-gzip' length 46786 bytes (45 KB)
==================================================
downloaded 45 KB

trying URL 'https://cloud.r-project.org/src/contrib/tfruns_1.5.0.tar.gz'
Content type 'application/x-gzip' length 2011046 bytes (1.9 MB)
==================================================
downloaded 1.9 MB

trying URL 'https://cloud.r-project.org/src/contrib/keras_2.6.0.tar.gz'
Content type 'application/x-gzip' length 3462992 bytes (3.3 MB)
==================================================
downloaded 3.3 MB

* installing *source* package ‘Rcpp’ ...
 package ‘Rcpp’ successfully unpacked and MD5 sums checked
 libs
g++  -I"/usr/share/R/include" -DNDEBUG -I../inst/include/     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-3.5.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c api.cpp -o api.o
/bin/bash: g++: command not found
make: *** [/usr/lib/R/etc/Makeconf:171: api.o] Error 127
ERROR: compilation failed for package ‘Rcpp’
* removing ‘/home/braingen/R/x86_64-pc-linux-gnu-library/3.5/Rcpp’
* installing *source* package ‘png’ ...
 package ‘png’ successfully unpacked and MD5 sums checked
 libs
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG      libpng-config --cflags -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-3.5.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c read.c -o read.o
/bin/bash: libpng-config: command not found
read.c:3:10: fatal error: png.h: No such file or directory
 #include <png.h>
          ^~~~~~~
compilation terminated.
make: *** [/usr/lib/R/etc/Makeconf:162: read.o] Error 1
ERROR: compilation failed for package ‘png’
* removing ‘/home/braingen/R/x86_64-pc-linux-gnu-library/3.5/png’
ERROR: dependencies ‘Rcpp’, ‘png’ are not available for package ‘reticulate’
* removing ‘/home/braingen/R/x86_64-pc-linux-gnu-library/3.5/reticulate’
ERROR: dependency ‘reticulate’ is not available for package ‘tfautograph’
* removing ‘/home/braingen/R/x86_64-pc-linux-gnu-library/3.5/tfautograph’
ERROR: dependency ‘reticulate’ is not available for package ‘tfruns’
* removing ‘/home/braingen/R/x86_64-pc-linux-gnu-library/3.5/tfruns’
ERROR: dependencies ‘reticulate’, ‘tfruns’, ‘tfautograph’ are not available for package ‘tensorflow’
* removing ‘/home/braingen/R/x86_64-pc-linux-gnu-library/3.5/tensorflow’
ERROR: dependencies ‘reticulate’, ‘tensorflow’, ‘tfruns’ are not available for package ‘keras’
* removing ‘/home/braingen/R/x86_64-pc-linux-gnu-library/3.5/keras’

Brain gen, [25.08.21 13:53]
The downloaded source packages are in
        ‘/tmp/RtmpxmyvE9/downloaded_packages’
Warning messages:
1: In install.packages("keras") :
  installation of package ‘Rcpp’ had non-zero exit status
2: In install.packages("keras") :
  installation of package ‘png’ had non-zero exit status
3: In install.packages("keras") :
  installation of package ‘reticulate’ had non-zero exit status
4: In install.packages("keras") :
  installation of package ‘tfautograph’ had non-zero exit status
5: In install.packages("keras") :
  installation of package ‘tfruns’ had non-zero exit status
6: In install.packages("keras") :
  installation of package ‘tensorflow’ had non-zero exit status
7: In install.packages("keras") :
  installation of package ‘keras’ had non-zero exit status
>

【问题讨论】:

好像没有安装g++,试试这个:***.com/q/50729550/6574038 请按照此处提到的说明进行操作tensorflow.rstudio.com/installation 【参考方案1】:

“png”包似乎由于缺少系统标头而未能安装。我在 docker 容器中尝试过,但无法在本地重现您的错误。两个想法: a) 也许您正在使用的 debian 映像中不包含一些额外的系统依赖项?也许像apt install png-dev 这样的东西可以让它工作。

b) 也许更新 R 的版本? R 3.5 是在 3 年前发布的,这可能是问题的根本原因,而 R 的当前发布版本是 4.1.1。

【讨论】:

另请注意,您可以通过sudo apt install r-cran-rcpp r-cran-png 满足这一点并依赖预制的二进制文件。当前 Debian 中的 ~ 1000 个其他 CRAN 软件包也是如此。至于 R 3.5——哎呀。请参阅cloud.r-project.org/bin/linux/debian,了解在保持 Debian 版本的同时获取 current R 的简单替代方法。

以上是关于如何使用 Linux Debian 正确安装 R keras的主要内容,如果未能解决你的问题,请参考以下文章

如何在离线 Debian 机器上安装 R 包?

Linux debian安装配置和使用PuTTY教程

Linux debian安装配置和使用PuTTY教程

debian 能使用dnf

如何正确安装 csdtoolbox-remote?

linux debian下如何制作.deb