2017-03-02 340 views
0

I was trying to use a R package called "XML", 但遇到了麻煩,安裝後使用它:如何指定安裝R包時使用哪個R lib?

# in R environment 
> library("XML") 
> XML::parseURI("") 
Error in XML::parseURI("") : cannot parse URI 

問題竟然是R找不到安裝在我的目錄「的libxml2」的最新版本:

echo $LD_LIBRARY_PATH /somewhere/Jun/Programme/libxml2-devel-2.9.1-2.1/usr/lib/: 

檢索有關libxml2的「XML」的版本信息鏈接到

> path = unclass(getLoadedDLLs()[["XML"]])$path 
> path 
[1] "/misc/home/Jun/Programme/R-3.3.1/lib64/R/library/XML/libs/XML.so" 
> system2("ldd",args=path) 
       linux-vdso.so.1 => (0x00007fff2a9e8000) 
       libxml2.so.2 => /usr/lib64/libxml2.so.2 (0x00002aefc088a000) # XML is using a common "libxml2.so.2" not the one I installed. 
       libz.so.1 => //home/Jun/Programme/zlib-1.2.11/lib/libz.so.1 (0x00002aefc0bc8000) 
       libm.so.6 => /lib64/libm.so.6 (0x00002aefc0de5000) 
       libdl.so.2 => /lib64/libdl.so.2 (0x00002aefc1068000) 
       ... 

任何建議這樣做?

爲了使 「XML」 鏈接到安裝在我的目錄中的libxml2, 我做出這樣的努力:爲libxml2的

  1. 設置PATH:

    回聲$ LD_LIBRARY_PATH

    /某處月/ 6 /計劃/ PCRE-8.40/lib中/:/某處月/ 6 /計劃/ XZ-5.2.3/lib中/:/某處月/ 6 /計劃/ zlib的-1.2.11 /有/:/某處月/ 6 /計劃/ zlib的-1.2.11/lib中/:/某處月/ 6 /計劃/ bzip2-1.0.6/lib中/:/某處月/ 6 /計劃/ bzip2-1.0.6/includ E /:/某處月/ 6 /計劃/ GCC-6.1.0/lib中/:/某處月/ 6 /計劃/ GCC-6.1.0/lib64下/:/某處月/ 6 /計劃/的libxml2-devel的-2.9.1- 2.1/usr/lib中/:/某處月/ 6 /計劃/捲曲7.52.1/lib中/:/某處月/ 6 /計劃/ libtool_CentOS6_64在/ usr/lib64下/:/家庭/申請/的openmpi-1.3.1/lib目錄下: /opt22/lsf83_exp/8.3/linux2.6-glibc2.3-x86_64/lib:/opt/ups/lib

  2. 重新編譯R 2與配置指定使用的lib 「--enable」 參數

    的./configure --prefix = $ HOME/Program/R-3.3.1 --enable-R-shlib LDFLAGS =「 - L/$ HOME/Program/zlib-1.2.11/lib -L ​​/ $ HOME/Program/bzip2-1.0 ./lib -L ​​/ $ HOME/Program/xz-5.2.3/lib -L ​​/ $ HOME/Program/pcre-8.40/lib -L ​​/ $ HOME/Program/curl-7.52.1/lib「CPPFLAGS = 「-I/$ HOME/Program/zlib-1.2.11/include -I/$ HOME/Program/bzip2-1.0.6/include - I/$ HOME/Program/xz-5.2.3/include -I/$ HOME/Program/pcre-8.40/include -I/$ HOME/Program/curl-7.52.1/include「

  3. install」 XML「的配置參數:

    biocLite(」XML「,configure.args =' - with-xml-config =」/ somewhere/Jun/Program/libxml2-devel-2.9.1-2.1/usr/bin/xml2-config「') BioC_mirror:http://bioconductor.org 使用Bioconductor 3.4(BiocInstaller 1.24.0),R 3.3.1(2016-06-21)。 安裝包(S) 'XML' 試圖URL 'http://cran.rstudio.com/src/contrib/XML_3.98-1.5.tar.gz'

    內容類型 '應用程序/ x-gzip的' 長度1599213個字節(1.5 MB)

    下載1.5 MB ...

但他們都不似乎工作:

* installing *source* package ‘XML’ ... 
** package ‘XML’ successfully unpacked and MD5 sums checked 
checking for gcc... gcc 
checking for C compiler default output file name... a.out 
checking whether the C compiler works... yes 
checking whether we are cross compiling... no 
checking 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... /bin/sed 
checking for pkg-config... /usr/bin/pkg-config 
User defined xml-config: /somewhere/Jun/Programme/libxml2-devel-2.9.1-2.1/usr/bin/xml2-config, XML Version: 2, XML2: yes 
USE_XML2 = yes 
SED_EXTENDED_ARG: -r 
Minor 9, Patch 1 for 2.9.1 
Located parser file -I/usr/include/libxml2/parser.h 
checking for gzopen in -lz... yes 
checking for xmlParseFile in -lxml2... yes 
checking for xmlHashSize in -lxml2... yes 
Using built-in xmlHashSize 
Checking DTD parsing (presence of externalSubset)... 
checking for xmlHashSize in -lxml2... yes 
Found xmlHashSize 
checking for xmlOutputBufferCreateBuffer in -lxml2... yes 
have xmlOutputBufferCreateBuffer() 
checking for xmlDocDumpFormatMemoryEnc in -lxml2... yes 
checking libxml/xmlversion.h usability... yes 
checking libxml/xmlversion.h presence... yes 
checking for libxml/xmlversion.h... yes 
Expat: FALSE 
Checking for return type of xmlHashScan element routine. 
No return value for xmlHashScan 
xmlNs has a context field 
Checking for cetype_t enumeration 
Using recent version of R with cetype_t enumeration type for encoding 
checking for xmlsec1-config... /usr/bin/xmlsec1-config 
nodegc default 
xml-debug default 
No XML_WITH_ZLIB enumeration value. 
Version has xmlHasFeature() 

**************************************** 
Configuration information: 

Libxml settings 

libxml include directory: -I/usr/include/libxml2 
libxml library directory: -lxml2 -lz -lm -ldl -lz -lxml2 
libxml 2:     -DLIBXML2=1 
+0

什麼'/somewhere/Jun/Programme/libxml2-devel-2.9.1-2.1/usr/bin/xml2-config --cflags --libs'的輸出? – nwellnhof

+0

@nwellnhof,hi nwellnhof,你可能會懷疑,'xml2-config --cflags -I/usr/include/libxml2 xml2-config --libs -lxml2 -lz -lm -ldl#xml2-config points在系統庫。 '我的xml2-config沒有指向我安裝的lib。我通過編譯而不是使用「rpm」來重新安裝來解決我的問題。感謝您的關注和建議。 – Jun

回答

0

我想我已經找到了解決辦法。我沒有使用rpm來安裝「libxml2」 (我很抱歉,在我的文章中沒有提及它;我沒有意識到它可能是我麻煩的原因),我應該從源代碼編譯「libxml2」。

對於有類似問題的人:

下載的libxml2 http://www.linuxfromscratch.org/blfs/view/svn/general/libxml2.html的當前版本,

上面的鏈接的指示。

兩個安裝點:

1.

./configure --prefix=$HOME/Programme --disable-static --with-history --with-zlib=/somewhere/Jun/Programme/zlib-1.2.11 && make 

你必須指定的zlib(--with);這也意味着你必須安裝zlib。我不得不添加「--with」使configure工作。

  1. 說明聲明您必須以root用戶身份調用「make install」,但不是,您不必這樣做。

  2. 爲您安裝的「libxml2」設置PATH

  3. 重新安裝R包「XML」。