R-package XML 安装失败及解决方式
安装R-package XML遇到的问题和解决方式
这个问题已经困扰了我很久很久一直找不到解决之法,后来终于找到了!
Fedora 27, R 3.5.0, libxml和libxml2以及开发包均已安装和更新,系统另有anacoda3。
遇到的问题:
直接在R下
>install.packages(“XML”) 并选择CRAN镜像后,出现安装错误,提示库版本不一致问题
(原错误已遗失,贴出来自 https://stackoverflow.com/questions/37035088/unable-to-install-r-package-due-to-xml-dependency-mismatch 的网友问题 )
trying URL 'https://cloud.r-project.org/src/contrib/XML_3.98-1.4.tar.gz'Content type 'application/x-gzip' length 1599214 bytes (1.5 MB)==================================================downloaded 1.5 MB* installing *source* package ‘XML’ ...** package ‘XML’ successfully unpacked and MD5 sums checkedchecking for gcc... gcc checking for C compiler default output file name... a.outchecking whether the C compiler works... yes checking whether we are cross compiling... nochecking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking how to run the C preprocessor... gcc -E checking for sed... /usr/local/Library/ENV/4.3/sed checking for pkg-config... /usr/local/bin/pkg-config checking for xml2-config... /Users/richiethomas/anaconda/bin/xml2-config USE_XML2 = yes SED_EXTENDED_ARG: -EMinor 9, Patch 2 for 2.9.2Located parser file -I/Users/richiethomas/anaconda/include/libxml2/parser.hChecking for 1.8: -I/Users/richiethomas/anaconda/include/libxml2Using libxml2.*checking for gzopen in -lz... yes checking for xmlParseFile in -lxml2... yesYou are trying to use a version 2.* edition of libxml but an incompatible library. The header files and library seem to be mismatched. If you have specified LIBXML_INCDIR, make certain to also specify an appropriate LIBXML_LIBDIR if the libxml2 library is not in the defaultdirectories.ERROR: configuration failed for package ‘XML’* removing ‘/usr/local/lib/R/3.2/site-library/XML’
按照 https://forums.fedoraforum.org/showthread.php?315915-can-not-install-xml-package-in-R 的提示,这应该是由于 “it looks from your output that R was looking for libxml-1.8 headers but found the libxml2 headers instead” 的关系,于是按照错误提示,系统目前默认从libxml2目录(anacoda3中的libxml2目录)中查找对应文件导致无法顺利编译,而解决方案应为将LIBXML_INCDIR以及LIBXML_DIR指定为libxml-1.8的对应目录,而为了以后python的使用着想,不建议采用链接题主所用的直接删除anacoda3的方式。
为了确认这一点,首先在terminal里:
$ xml2-config --cflags
输出结果为(根据不同用户习惯anaconda安装路径不同):
-I/data/home/heshuai/anaconda3/include/libxml2 -I/data/home/heshuai/anaconda3/include
而
$ locate xml2-config
则输出
/usr/bin/xml2-config
/usr/share/man/man1/xml2-config.1.gz
所以需要在安装XML的过程中(本人也只尝试了第二条),
1) 或者在.bashrc中将LIBXML_INCDIR设置为
$ /usr/bin/xml2-config --cflag的输出目录 (https://support.bioconductor.org/p/1639/),
再完成后续安装 (作者本人未尝试);
2) 或者参考https://stackoverflow.com/questions/40682615/cannot-install-xml-package-in-r/48355121#48355121 的第一条回答,
进入R,
>Sys.setenv(XML_CONFIG="/usr/bin/xml2-config") #指定安装时libxml2的目录
>install.packages("XML")
问题解决。
虽然网上有教程用conda install r-xml
但是conda对应的最新版本是 linux-64 v3.98_1.19,并不是最新的包, 而RCRAN 上的最新版本是 v3.98_1.2。因此, 即使用conda 安装了1.19,在安装其它包的时候仍然会提示更新XML,依然会出现上述问题。建议大家采用上述解决方案安装最新版本的XML包。
http://blog.sciencenet.cn/blog-773206-1155793.html