在 CentOS 中安装软件包时遇到问题:无法加载 Internet 例程

trouble installing packages in CentOS: internet routines cannot be loaded

我在更新 R 后在 CentOS 上的 R 中安装包时遇到了一些问题。这是我尝试在 R 中安装包时发生的情况的示例:

> install.packages("ggplot2")
Installing package into '/home/albers/R/x86_64-pc-linux-gnu-library/3.2'
(as 'lib' is unspecified)
--- Please select a CRAN mirror for use in this session ---
Error in download.file(url, destfile = f, quiet = TRUE) :
  internet routines cannot be loaded
In addition: Warning message:
In download.file(url, destfile = f, quiet = TRUE) :
  unable to load shared object '/usr/local/lib64/R/modules//internet.so':
  /usr/local/lib64/R/modules//internet.so: undefined symbol: curl_multi_wait
HTTPS CRAN mirror

 1: 0-Cloud [https]                2: Austria [https]
 3: Chile [https]                  4: China (Beijing 4) [https]
 5: Colombia (Cali) [https]        6: France (Lyon 2) [https]
 7: France (Paris 2) [https]       8: Germany (M▒nster) [https]
 9: Iceland [https]               10: Mexico (Mexico City) [https]
11: Russia (Moscow) [https]       12: Spain (A Coru▒a) [https]
13: Switzerland [https]           14: UK (Bristol) [https]
15: UK (Cambridge) [https]        16: USA (CA 1) [https]
17: USA (KS) [https]              18: USA (MI 1) [https]
19: USA (TN) [https]              20: USA (TX) [https]
21: USA (WA) [https]              22: (HTTP mirrors)


Selection: 1
Warning: unable to access index for repository https://cran.rstudio.com/src/contrib:
  internet routines cannot be loaded
Warning message:
package 'ggplot2' is not available (for R version 3.2.5)

所以我花了一些时间搜索错误信息。我更新了我的 curl 版本,现在是最新的:

$ curl -V
curl 7.48.0 (x86_64-pc-linux-gnu) libcurl/7.48.0 zlib/1.2.8
Protocols: dict file ftp gopher http imap pop3 rtsp smtp telnet tftp
Features: IPv6 Largefile libz UnixSockets

仍然无法安装软件包并且收到相同的错误消息。所以我尝试按照 this post 的说明进行操作,特别是将以下命令添加到我的 .bash_profile:

export LD_LIBRARY_PATH=$TOOLS/curl-7.48.0/lib:$LD_LIBRARY_PATH

我再次收到有关 R 无法加载共享对象的相同错误消息。归根结底,这是一个下载问题,因为 download.file 也失败了。这是我的 sessionInfo():

R version 3.2.5 (2016-04-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS release 6.2 (Final)

locale:
 [1] LC_CTYPE=en_US.iso885915       LC_NUMERIC=C
 [3] LC_TIME=en_US.iso885915        LC_COLLATE=en_US.iso885915
 [5] LC_MONETARY=en_US.iso885915    LC_MESSAGES=en_US.iso885915
 [7] LC_PAPER=en_US.iso885915       LC_NAME=C
 [9] LC_ADDRESS=C                   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.iso885915 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

我可以使用 wgetcurl 下载文件,但是一旦我启动 R,我就无法下载任何东西。

有人对我如何解决这个问题有什么建议吗?

像这样尝试。

install.packages("ggplot2", repos="http://cran.cnr.berkeley.edu")

或者就在您安装它之前将您的下载工具更改为其他工具,即在 Linux 上您可以按如下方式尝试 wget。

options(download.file.method = "wget")

请注意,我为 http 删除了 https。我有一个类似的错误...

Selection: 1
Warning: unable to access index for repository https://cran.rstudio.com/src/contrib:
  unsupported URL scheme
Warning message:
package ‘ggplot2’ is not available (for R version 3.2.3) 

如果您查看问题中以下行的输出...

Yours
Protocols: dict file ftp gopher http imap pop3 rtsp smtp telnet tftp
Mine (Also Centos 6)
Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp 

您的 curl 缺少 https 支持。您的输出中也存在关于 curl_multi_wait 的错误。这是在 7.28.0 中添加的。

https://curl.haxx.se/libcurl/c/curl_multi_wait.html

如果您需要在本地构建 curl,请执行此操作

mkdir -p $HOME/curl
cd $HOME/curl
git clone https://github.com/curl/curl.git
cd curl
bash buildconf
./configure --prefix=$HOME/libcurl
make
make install

此时您需要在 .bash_profile 中设置您的 LD_LIBRARY_PATH 即

export LD_LIBRARY_PATH=$HOME/libcurl/lib:$LD_LIBRARY_PATH

然后注销并重新登录或者

source ~/.bash_profile

我想我在去年夏天进行 R 3.2.* 升级之前回答过一次类似的问题。使用 Ubuntu 12.04 的 Travis CI 也有类似的问题。

一个相当简单的解决方法是告诉 R 使用你可能拥有的 external wgetcurl 二进制文件(并且需要https-ready)下载。所以试试 eg

R> options("download.file.method"="wget")

设置后,我可以从所需的非 https 主机下载所需的包:

R> install.packages("ggplot2", repos="http://cran.cnr.berkeley.edu")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
--2016-04-26 18:29:16--  http://cran.cnr.berkeley.edu/src/contrib/ggplot2_2.1.0.tar.gz
Resolving cran.cnr.berkeley.edu (cran.cnr.berkeley.edu)... 169.229.201.201, 2607:f140:0:8000::201
Connecting to cran.cnr.berkeley.edu (cran.cnr.berkeley.edu)|169.229.201.201|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1571788 (1.5M) [application/x-gzip]
Saving to: ‘/tmp/RtmpwWvA3s/downloaded_packages/ggplot2_2.1.0.tar.gz’

/tmp/RtmpwWvA3s/downloaded_packages/ggplot2_2.1.0.ta 100%[========================================================================================================================>]   1.50M  1.32MB/s   in 1.1s   

2016-04-26 18:29:17 (1.32 MB/s) - ‘/tmp/RtmpwWvA3s/downloaded_packages/ggplot2_2.1.0.tar.gz’ saved [1571788/1571788]

* installing *source* package ‘ggplot2’ ...
** package ‘ggplot2’ successfully unpacked and MD5 sums checked
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (ggplot2)

The downloaded source packages are in
        ‘/tmp/RtmpwWvA3s/downloaded_packages’

您可以在~/.Rprofile或相应的Rprofile.site中设置选项。