多个R包无法使用curl包

15

我刚刚安装了Ubuntu 18.04,并成功安装了R版本3.5.1。但是在安装像plotly这样的R包时出现问题。似乎curl和httr这些包不可用。完整的错误信息如下:

> install.packages("plotly")
Installing package into ‘/home/lualeperez/R/x86_64-pc-linux-gnu-library/3.5’
(as ‘lib’ is unspecified)
also installing the dependencies ‘curl’, ‘openssl’, ‘httr’

trying URL 'https://cloud.r-project.org/src/contrib/curl_3.2.tar.gz'
Content type 'application/x-gzip' length 367047 bytes (358 KB)
==================================================
downloaded 358 KB

trying URL 'https://cloud.r-project.org/src/contrib/openssl_1.0.2.tar.gz'
Content type 'application/x-gzip' length 1194883 bytes (1.1 MB)
==================================================
downloaded 1.1 MB

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

trying URL 'https://cloud.r-project.org/src/contrib/plotly_4.8.0.tar.gz'
Content type 'application/x-gzip' length 1860673 bytes (1.8 MB)
==================================================
downloaded 1.8 MB

* installing *source* package ‘curl’ ...
** package ‘curl’ successfully unpacked and MD5 sums checked
Package libcurl was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcurl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libcurl' found
Package libcurl was not found in the pkg-config search path.
Perhaps you should add the directory containing `libcurl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libcurl' found
Using PKG_CFLAGS=
Using PKG_LIBS=-lcurl
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because libcurl was not found. Try installing:
 * deb: libcurl4-openssl-dev (Debian, Ubuntu, etc)
 * rpm: libcurl-devel (Fedora, CentOS, RHEL)
 * csw: libcurl_dev (Solaris)
If libcurl is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libcurl.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------------------------------------------------
ERROR: configuration failed for package ‘curl’
* removing ‘/home/lualeperez/R/x86_64-pc-linux-gnu-library/3.5/curl’
* installing *source* package ‘openssl’ ...
** package ‘openssl’ successfully unpacked and MD5 sums checked
Using PKG_CFLAGS=
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because openssl was not found. Try installing:
 * deb: libssl-dev (Debian, Ubuntu, etc)
 * rpm: openssl-devel (Fedora, CentOS, RHEL)
 * csw: libssl_dev (Solaris)
 * brew: openssl@1.1 (Mac OSX)
If openssl is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a openssl.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------------------------------------------------
ERROR: configuration failed for package ‘openssl’
* removing ‘/home/lualeperez/R/x86_64-pc-linux-gnu-library/3.5/openssl’
ERROR: dependencies ‘curl’, ‘openssl’ are not available for package ‘httr’
* removing ‘/home/lualeperez/R/x86_64-pc-linux-gnu-library/3.5/httr’
ERROR: dependency ‘httr’ is not available for package ‘plotly’
* removing ‘/home/lualeperez/R/x86_64-pc-linux-gnu-library/3.5/plotly’

The downloaded source packages are in
    ‘/tmp/RtmpNTZBPJ/downloaded_packages’
Warning messages:
1: In install.packages("plotly") :
  installation of package ‘curl’ had non-zero exit status
2: In install.packages("plotly") :
  installation of package ‘openssl’ had non-zero exit status
3: In install.packages("plotly") :
  installation of package ‘httr’ had non-zero exit status
4: In install.packages("plotly") :
  installation of package ‘plotly’ had non-zero exit status

我试图通过执行安装libcurl4的操作来解决这个问题

sudo apt-get install libcurl4

但是系统会移除所有的r-base依赖项。

我还没有尝试使用httr软件包解决这个问题。

有人知道如何解决这个问题吗?


你需要安装开发库libcurl4-openssl-dev(如消息所示),而不是你正在安装的运行时库libcurl4。但是,正如下面我的回答建议的那样,你也可以安装二进制包并完成安装。 - Dirk Eddelbuettel
我尝试安装libcurl4-openssl-dev,但系统告诉我先安装libcurl4,当我尝试安装后者时,系统又告诉我它要卸载r-base。当你说我应该安装一个二进制包时,我实在不太明白。 - Alejandro Perez
@DirkEddelbuettel 当我尝试在使用r-base Docker镜像创建的容器中安装“httr”包时,遇到了同样的问题。我的install.packages("httr", dependencies = TRUE)报告了三个ANTICONF ERROR,抱怨缺少“libcurl4-openssl-dev”,“libssl-dev”和“libxml2-dev”。然后我使用sudo apt install在终端上安装了这三个软件包,并且apt list确认它们已被安装,但是“httr”的安装仍然失败,出现了三个ANTICONF ERROR。出了什么问题? - elarry
如果您在编译时遇到问题,我强烈建议您继续执行sudo apt install r-cran-httr。另请参阅https://eddelbuettel.github.io/r2u/以获取Ubuntu上*所有*CRAN的信息。 - Dirk Eddelbuettel
3个回答

16

我遇到了相同的问题,这是我找到的解决方案:

由于仅安装libcurl4-openssl-dev会删除所有r-base软件包,所以我做的是

sudo apt-get install libcurl4-openssl-dev r-base

随后

R -q -e "install.packages(c('curl'))"

而且它起作用了。

唯一的问题是它会升级你的 R 版本,但如果你已经使用最新版本,则不是问题。


太好了。我使用这个方法成功安装了“car”包,这正是我的目标。 - wayneeusa

10
你正在尝试从源代码编译。这有时会涉及所谓的“构建依赖项”。你缺少它们,并且由于进行了多个安装而忽略了(有些清晰的)错误消息,因此你可能会感到不知所措。
因此,第一个提示是一次只安装一个软件包。
第二个提示:请注意,许多(如果不是全部)都可以在Ubuntu中获得。所以只需执行
sudo apt install r-cran-curl

安装例如 curl。其他软件也是这样安装。

第三个提示:在Michael的PPA中,为Ubuntu提供了超过3000个CRAN软件包。阅读此README并前往此PPA(只要您需要3.5版,这是您需要的)。


1
非常感谢您的答复。如果问题很简单,我很抱歉,因为我对此还不是很了解。我尝试安装r-cran-curl但系统告诉我首先要安装libcurl4。如果我尝试安装这个软件,系统会告诉我它将卸载r-base。 - Alejandro Perez
我按照 https://cloud.r-project.org/bin/linux/ubuntu/README.html 和 https://launchpad.net/~marutter/+archive/ubuntu/c2d4u3.5 中的说明进行操作,然后运行 sudo apt-get update。接着我尝试安装 r-cran-curl,但出现了相同的错误信息。 - Alejandro Perez

0

Fedora 36:

dnf install cmake
dnf install openssl-devel
dnf install libcurl-devel.x86_64

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接