R语言 onLoad在loadNamespace()中为“utils”加载失败,详细信息

piwo6bdm  于 2023-04-09  发布在  其他
关注(0)|答案(2)|浏览(282)

我目前正在构建一个distroless R镜像(尽管我不精通R)
我目前正在从https://cloud.r-project.org/bin/linux/debian/buster-cran35/中提取用于amd64架构的deb包。
我能够从创建的映像交互式地运行R,然而,一些核心库没有正确加载,并且终端中有关故障原因的信息很少。
下面是运行以下命令的输出:R --verbose

'verbose' and 'quietly' are both true; being verbose then ..
now dyn.load("/usr/lib/R/library/methods/libs/methods.so") ...

R version 3.6.2 (2019-12-12) -- "Dark and Stormy Night"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

'verbose' and 'quietly' are both true; being verbose then ..
'verbose' and 'quietly' are both true; being verbose then ..
now dyn.load("/usr/lib/R/library/utils/libs/utils.so") ...
Garbage collection 1 = 0+0+1 (level 2) ...
12.0 Mbytes of cons cells used (35%)
3.1 Mbytes of vectors used (5%)
Error: package or namespace load failed for 'utils':
 .onLoad failed in loadNamespace() for 'utils', details:
  call: system(paste(which, shQuote(names[i])), intern = TRUE, ignore.stderr = TRUE)
  error: error in running command
'verbose' and 'quietly' are both true; being verbose then ..
now dyn.load("/usr/lib/R/library/grDevices/libs/grDevices.so") ...
'verbose' and 'quietly' are both true; being verbose then ..
now dyn.load("/usr/lib/R/library/graphics/libs/graphics.so") ...
'verbose' and 'quietly' are both true; being verbose then ..
shared object ''utils.so'' already loaded
Error: package or namespace load failed for 'stats':
 .onLoad failed in loadNamespace() for 'utils', details:
  call: system(paste(which, shQuote(names[i])), intern = TRUE, ignore.stderr = TRUE)
  error: error in running command

www.example.com的所有依赖库utils.so都可以通过ldd命令找到。
ldd www.example.com链接命令的输出utils.so:

/ # ldd /usr/lib/R/library/utils/libs/utils.so
    linux-vdso.so.1 (0x00007ffe772f9000)
    libR.so => /usr/lib/libR.so (0x00007f127acdf000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f127ab1e000)
    libblas.so.3 => /usr/lib/x86_64-linux-gnu/libblas.so.3 (0x00007f127aac3000)
    libgfortran.so.5 => /usr/lib/x86_64-linux-gnu/libgfortran.so.5 (0x00007f127a855000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f127a6d2000)
    libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007f127a690000)
    libreadline.so.7 => /lib/x86_64-linux-gnu/libreadline.so.7 (0x00007f127a441000)
    libpcre2-8.so.0 => /usr/lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f127a3bc000)
    libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f127a348000)
    liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f127a320000)
    libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007f127a30d000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f127a0ef000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f127a0e3000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f127a0de000)
    libicuuc.so.63 => /usr/lib/x86_64-linux-gnu/libicuuc.so.63 (0x00007f1279f0f000)
    libicui18n.so.63 => /usr/lib/x86_64-linux-gnu/libicui18n.so.63 (0x00007f1279c34000)
    libgomp.so.1 => /usr/lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f1279c03000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f1279be2000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f127b17f000)
    libopenblas.so.0 => /usr/lib/x86_64-linux-gnu/libopenblas.so.0 (0x00007f12779fc000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f12779e2000)
    libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007f12779b4000)
    libicudata.so.63 => /usr/lib/x86_64-linux-gnu/libicudata.so.63 (0x00007f1275fc4000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f1275e40000)

我可能错过了什么?
"utils.so" already loaded表示什么?

gcuhipw9

gcuhipw91#

我觉得你没说“哪个”。
在这个代码块system(paste(which, shQuote(names[i])), intern = TRUE, ignore.stderr = TRUE)中,which是来自Sys.which的对象,其值是字符串“/usr/bin/which”。
您应该尝试安装which

zzwlnbp8

zzwlnbp82#

啊!我终于想出了如何解决这个愚蠢的问题!还有GEE,感谢AWS Lambda团队没有在你的基本“Amazon Linux 2”运行时中包含Unix(GNU)原语“/usr/bin/which”工具-啊!
所以,除了弄清楚如何包含'which'的一个版本之外,这个问题实际上更深一层!你实际上必须用'which'二进制文件所在的 where 重新构建R!这是因为R使用system()并且想要'which'命令的完整路径。
在正常情况下,./configure会找出“which "的位置,然后将该路径嵌入到构建系统中”@WHICH@“所在的任何位置(结果是src/library/base/R/unix/system.unix.R)。在EC2的基本Amazon Linux 2 AMI下,这恰好是大多数unix系统所期望的:/usr/bin/which
然而,由于AWS Lambda的“Amazon linux 2”运行时是预构建的,并且不包括“which”-您不能直接将“which”安装到/usr/bin中。您必须将其放置在/opt下的某个位置,例如在bin/中将其放置在/opt/bin下;或者我实际上把它放在了R/bin中的R的位置。我有没有提到:啊?
所以,你要做的是:
1.将/usr/bin/which复制到/opt/R/bin/which(假设你要将它与R分层).基本上,cp /usr/bin/which /opt/R/bin.注意,你真的需要先做这一步(好吧,在你解开你的R源代码并将它移动/重命名为/opt/R之后).
1.现在运行./configure,不过需要先为WHICH定义一个要配置的环境变量。例如:

WHICH=/opt/R/bin/which ./configure --prefix=/opt/R/ --exec-prefix=/opt/R/ --with-libpth-prefix=/opt/ --without-recommended-packages --without-x

这将覆盖configure搜索“which”并将“which”定义为在生成系统上找到的任何位置。
1.在你确定你已经把'which'放到了你告诉./configure about的目录中之后,然后运行make。因为你告诉configure一个不同的位置,它需要在构建过程中存在,因为它知道的'which'在构建过程中也实际使用。如果在构建过程中没有找到它,那么当你运行R时,你会遇到其他奇怪的问题。
1.将任何缺少的系统库添加到/opt/R/lib中。例如,对于AWS Lambda 'Amazon linux 2'运行时,您将需要添加:libgfortran.so.4、libquadmath.so.0、libpcre2-8.so.0、libgomp.so.1
1.添加一些基本的“必需”包,以运行合理的 Bootstrap :

./bin/Rscript -e 'chooseCRANmirror(graphics=FALSE, ind=34); install.packages(c("jsonlite","httr","logging"))'

1.将整个kit-n-kaboodle打包并安装为第一层:

(cd /opt; zip -qr ~/R-runtime.zip R/bin/ R/lib/ R/etc R/library/ R/modules/)

瞧!你现在应该有一个真正起作用的R层了!

相关问题