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 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM