||
系统和其他:
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/opt/pya/anaconda3/include/libxml2 -I/opt/pya/anaconda3/include
而
$ locate xml2-config
则输出
/opt/pya/anaconda3/bin/xml2-config
/opt/pya/anaconda3/lib/cmake/libxml2/libxml2-config.cmake
/opt/pya/anaconda3/pkgs/libxml2-2.9.7-h26e45fe_0/bin/xml2-config
/opt/pya/anaconda3/pkgs/libxml2-2.9.7-h26e45fe_0/lib/cmake/libxml2/libxml2-config.cmake
/opt/pya/anaconda3/pkgs/libxml2-2.9.7-h26e45fe_0/share/man/man1/xml2-config.1
/opt/pya/anaconda3/pkgs/libxml2-2.9.8-h26e45fe_1/bin/xml2-config
/opt/pya/anaconda3/pkgs/libxml2-2.9.8-h26e45fe_1/lib/cmake/libxml2/libxml2-config.cmake
/opt/pya/anaconda3/pkgs/libxml2-2.9.8-h26e45fe_1/share/man/man1/xml2-config.1
/opt/pya/anaconda3/share/man/man1/xml2-config.1
/usr/bin/xml2-config
/usr/lib64/cmake/libxml2/libxml2-config.cmake
/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")
问题解决。
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-12-22 00:38
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社