conda中的R安装xml2包(Ubuntu)

miniconda3中R安装xml2报错:(安装do包时发现缺少xml2和rvest包,单独安装xml2发现以下问题,libxml2及libxml2-dev安装后发现rvest包也能安装了)

trying URL 'https://mirrors.sjtug.sjtu.edu.cn/cran/src/contrib/xml2_1.3.5.tar.gz'
Content type 'application/gzip' length 272664 bytes (266 KB)
==================================================
downloaded 266 KB

* installing *source* package ‘xml2’ ...
** package ‘xml2’ successfully unpacked and MD5 sums checked
** using staged installation
Using PKG_CFLAGS=
Using PKG_LIBS=-lxml2
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because libxml-2.0 was not found. Try installing:
 * deb: libxml2-dev (Debian, Ubuntu, etc)
 * rpm: libxml2-devel (Fedora, CentOS, RHEL)
 * csw: libxml2_dev (Solaris)
If libxml-2.0 is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libxml-2.0.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 ‘xml2’
* removing ‘/home/ubuntu/miniconda3/envs/R/lib/R/library/xml2’

The downloaded source packages are in
    ‘/tmp/RtmpN2qcLn/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
Warning message:
In install.packages("xml2") :
  installation of package ‘xml2’ had non-zero exit status

根据提示是缺少依赖项libxml2-dev,于是退出R,查询后发现确实没有,于是在当前环境中安装libxml2-dev(必须是r-base所在的环境)

conda list      #列出当前环境安装的所有软件
conda list libxml2      #加上软件名称,指定查询想看的软件
conda list libxml2-dev

使用的清华镜像源,没找到libxml2-dev, 在anaconda官方(https://anaconda.org/conda-forge/)中查询后,发现有 libxml2-devel-cos7-x86_64,安装如下(尝试后发现libxml2和libxml2-devel都需要安装):

conda install libxml2
conda install -c conda-forge libxml2-devel-cos7-x86_64      #指定官方地址下载

安装成功后,打开R,重新安装xml2

chooseCRANmirror()      #选择一个离得近的镜像源
install.package("xml2")

成功安装!

你可能感兴趣的:(conda中的R安装xml2包(Ubuntu))