简体   繁体   English

由于 XML 依赖不匹配,无法安装 R 包

[英]Unable to install R package due to XML dependency mismatch

I launched R in my command-line and typed the following:我在命令行中启动了 R 并输入了以下内容:

install.packages("XML")

After selecting a mirror site, I saw the following output:选择镜像站点后,看到如下输出:

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 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... /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: -E
Minor 9, Patch 2 for 2.9.2
Located parser file -I/Users/richiethomas/anaconda/include/libxml2/parser.h
Checking for 1.8:  -I/Users/richiethomas/anaconda/include/libxml2
Using libxml2.*
checking for gzopen in -lz... yes
checking for xmlParseFile in -lxml2... yes
You 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 default
directories.
ERROR: configuration failed for package ‘XML’
* removing ‘/usr/local/lib/R/3.2/site-library/XML’

The downloaded source packages are in
    ‘/private/var/folders/jy/0cwn40p951xc7f1480z3sxzm0000gn/T/RtmpvWMrkH/downloaded_packages’
Warning message:
In install.packages("XML") :
  installation of package ‘XML’ had non-zero exit status

I Googled around and found this link , which suggested running the 'which xmllint' command in the command line to find any XML installations which might conflict with the one R depends on.我在谷歌上搜索并找到了这个链接,它建议在命令行中运行“which xmllint”命令来查找任何可能与 R 依赖的 XML 安装冲突的 XML 安装。 The output when I ran it was:我运行它时的输出是:

/Users/richiethomas/anaconda/bin/xmllint

Correct me if I'm wrong, but it appears that my Python installation has an XML dependency which conflicts with the one R wants to download.如果我错了,请纠正我,但我的 Python 安装似乎有一个 XML 依赖项,该依赖项与 R 想要下载的依赖项冲突。 Is this right?这是对的吗? And if so, how can I fix it so that both Python and R are installed on my machine?如果是这样,我该如何修复它以便在我的机器上安装 Python 和 R?

EDIT: I am using OSX.编辑:我正在使用 OSX。 I ran "brew install libxml2" but Homebrew said it was already installed.我运行了“brew install libxml2”,但 Homebrew 说它已经安装了。

EDIT #2: I tried un-installing and re-installing R via Homebrew, and I am still getting the same error.编辑 #2:我尝试通过 Homebrew 卸载并重新安装 R,但我仍然遇到相同的错误。

EDIT #3: I ran "brew info libxml2" and saw that there is an "--with-python" flag which enables a build with Python support.编辑 #3:我运行了“brew info libxml2”,看到有一个“--with-python”标志,它可以使用 Python 支持进行构建。 I also noticed the following:我还注意到以下几点:

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/libxml2/lib
    CPPFLAGS: -I/usr/local/opt/libxml2/include

I ran "brew uninstall libxml2" and then "brew install libxml2 --with-python", and then set the above 2 environment variables using the "export" command.我运行“brew uninstall libxml2”,然后运行“brew install libxml2 --with-python”,然后使用“export”命令设置上述2个环境变量。 Then I re-ran R and again tried to install the XML package.然后我重新运行 R 并再次尝试安装 XML 包。 I saw dozens of warnings of the type "passing argument to parameter here" (see below), followed by a non-zero exit code:我看到了许多“在此处将参数传递给参数”类型的警告(见下文),然后是非零退出代码:

    * 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... /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: -E
Minor 9, Patch 2 for 2.9.2
Located parser file -I/Users/richiethomas/anaconda/include/libxml2/parser.h
Checking for 1.8:  -I/Users/richiethomas/anaconda/include/libxml2
Using libxml2.*
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... no
nodegc default 
xml-debug default 
Version has XML_WITH_ZLIB
Version has xmlHasFeature()

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

Libxml settings

libxml include directory: -I/Users/richiethomas/anaconda/include/libxml2
libxml library directory: -L/Users/richiethomas/anaconda/lib -lxml2 -lz -liconv -lm -lz  -lxml2
libxml 2:                 -DLIBXML2=1

Compilation flags:         -DLIBXML -I/Users/richiethomas/anaconda/include/libxml2 -DUSE_EXTERNAL_SUBSET=1 -DROOT_HAS_DTD_NODE=1 -DDUMP_WITH_ENCODING=1 -DUSE_XML_VERSION_H=1 -DXML_ELEMENT_ETYPE=1 -DXML_ATTRIBUTE_ATYPE=1 -DNO_XML_HASH_SCANNER_RETURN=1 -DLIBXML_NAMESPACE_HAS_CONTEXT=1 -DHAVE_R_CETYPE_T=1 -DHAVE_XML_WITH_ZLIB=1 -DHAVE_XML_HAS_FEATURE=1 -DUSE_R=1 -D_R_=1  -DHAVE_VALIDITY=1 -DXML_REF_COUNT_NODES=1 
Link flags:               -L/Users/richiethomas/anaconda/lib -lxml2 -lz -liconv -lm -lz  -lxml2

****************************************
configure: creating ./config.status
config.status: creating src/Makevars
config.status: creating R/supports.R
config.status: creating inst/scripts/RSXML.csh
config.status: creating inst/scripts/RSXML.bsh
** libs
clang -I/usr/local/Cellar/r/3.2.4_1/R.framework/Resources/include -DNDEBUG -DLIBXML -I/Users/richiethomas/anaconda/include/libxml2 -DUSE_EXTERNAL_SUBSET=1 -DROOT_HAS_DTD_NODE=1 -DDUMP_WITH_ENCODING=1 -DUSE_XML_VERSION_H=1 -DXML_ELEMENT_ETYPE=1 -DXML_ATTRIBUTE_ATYPE=1 -DNO_XML_HASH_SCANNER_RETURN=1 -DLIBXML_NAMESPACE_HAS_CONTEXT=1 -DHAVE_R_CETYPE_T=1 -DHAVE_XML_WITH_ZLIB=1 -DHAVE_XML_HAS_FEATURE=1 -DUSE_R=1 -D_R_=1  -DHAVE_VALIDITY=1 -DXML_REF_COUNT_NODES=1  -I. -DLIBXML2=1 -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl/include -I/usr/local/include    -fPIC  -g -O2  -c DocParse.c -o DocParse.o
DocParse.c:375:60: warning: passing 'const char *' to parameter of type 'const xmlChar *' (aka 'const unsigned char *') converts between
      pointers to integer types with different sign [-Wpointer-sign]
    SET_STRING_ELT(VECTOR_ELT(rdoc, FILE_ELEMENT_NAME), 0, ENC_COPY_TO_USER_STRING(doc->name ? XMLCHAR_TO_CHAR(doc->name) : fileName));
                                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Utils.h:235:74: note: expanded from macro 'ENC_COPY_TO_USER_STRING'
#define ENC_COPY_TO_USER_STRING(x)  CreateCharSexpWithEncoding(encoding, CHAR_TO_XMLCHAR (x)) 
                                                                         ^~~~~~~~~~~~~~~~~~~
./Utils.h:12:31: note: expanded from macro 'CHAR_TO_XMLCHAR'
#define CHAR_TO_XMLCHAR(val)  ((xmlChar *) val)
                              ^~~~~~~~~~~~~~~~~
./Utils.h:220:73: note: passing argument to parameter 'str' here
SEXP CreateCharSexpWithEncoding(const xmlChar *encoding, const xmlChar *str);

.....

/usr/local/Cellar/r/3.2.4_1/R.framework/Resources/include/Rinternals.h:822:28: note: passing argument to parameter here
    SEXP Rf_mkChar(const char *);
                               ^
    schema.c:122:25: warning: passing 'const char *' to parameter of type 'const xmlChar *' (aka 'const unsigned char *') converts between pointers
          to integer types with different sign [-Wpointer-sign]
       p = xmlHashLookup(t, CHAR_DEREF(STRING_ELT(name, 0)));
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ./RSCommon.h:140:27: note: expanded from macro 'CHAR_DEREF'
      #define CHAR_DEREF(x)   CHAR((x))
                              ^~~~~~~~~
    /usr/local/Cellar/r/3.2.4_1/R.framework/Resources/include/Rinternals.h:440:18: note: expanded from macro 'CHAR'
    #define CHAR(x)         R_CHAR(x)
                            ^~~~~~~~~
    /Users/richiethomas/anaconda/include/libxml2/libxml/hash.h:171:22: note: passing argument to parameter 'name' here
                                             const xmlChar *name);
                                                            ^
    2 warnings generated.
    clang -I/usr/local/Cellar/r/3.2.4_1/R.framework/Resources/include -DNDEBUG -DLIBXML -I/Users/richiethomas/anaconda/include/libxml2 -DUSE_EXTERNAL_SUBSET=1 -DROOT_HAS_DTD_NODE=1 -DDUMP_WITH_ENCODING=1 -DUSE_XML_VERSION_H=1 -DXML_ELEMENT_ETYPE=1 -DXML_ATTRIBUTE_ATYPE=1 -DNO_XML_HASH_SCANNER_RETURN=1 -DLIBXML_NAMESPACE_HAS_CONTEXT=1 -DHAVE_R_CETYPE_T=1 -DHAVE_XML_WITH_ZLIB=1 -DHAVE_XML_HAS_FEATURE=1 -DUSE_R=1 -D_R_=1  -DHAVE_VALIDITY=1 -DXML_REF_COUNT_NODES=1  -I. -DLIBXML2=1 -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl/include -I/usr/local/include    -fPIC  -g -O2  -c xmlsecurity.c -o xmlsecurity.o
    clang -I/usr/local/Cellar/r/3.2.4_1/R.framework/Resources/include -DNDEBUG -DLIBXML -I/Users/richiethomas/anaconda/include/libxml2 -DUSE_EXTERNAL_SUBSET=1 -DROOT_HAS_DTD_NODE=1 -DDUMP_WITH_ENCODING=1 -DUSE_XML_VERSION_H=1 -DXML_ELEMENT_ETYPE=1 -DXML_ATTRIBUTE_ATYPE=1 -DNO_XML_HASH_SCANNER_RETURN=1 -DLIBXML_NAMESPACE_HAS_CONTEXT=1 -DHAVE_R_CETYPE_T=1 -DHAVE_XML_WITH_ZLIB=1 -DHAVE_XML_HAS_FEATURE=1 -DUSE_R=1 -D_R_=1  -DHAVE_VALIDITY=1 -DXML_REF_COUNT_NODES=1  -I. -DLIBXML2=1 -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/opt/openssl/include -I/usr/local/include    -fPIC  -g -O2  -c xpath.c -o xpath.o
    xpath.c:36:41: warning: passing 'const xmlChar *' (aka 'const unsigned char *') to parameter of type 'const char *' converts between pointers
          to integer types with different sign [-Wpointer-sign]
              SET_NAMES(ref, ScalarString(mkCharCE(el->name, encoding)));
                                                   ^~~~~~~~
    /usr/local/Cellar/r/3.2.4_1/R.framework/Resources/include/Rdefines.h:135:54: note: expanded from macro 'SET_NAMES'
    #define SET_NAMES(x, n)         setAttrib(x, R_NamesSymbol, n)
                                                                ^
    /usr/local/Cellar/r/3.2.4_1/R.framework/Resources/include/Rinternals.h:889:30: note: passing argument to parameter here
    SEXP Rf_mkCharCE(const char *, cetype_t);
                                 ^
    1 warning generated.
    clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/Cellar/r/3.2.4_1/R.framework/Resources/lib -L/usr/local/opt/gettext/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/openssl/lib -L/usr/local/lib -o XML.so DocParse.o EventParse.o ExpatParse.o HTMLParse.o NodeGC.o RSDTD.o RUtils.o Rcatalog.o Utils.o XMLEventParse.o XMLHashTree.o XMLTree.o fixNS.o libxmlFeatures.o schema.o xmlsecurity.o xpath.o -L/Users/richiethomas/anaconda/lib -lxml2 -lz -liconv -lm -lz -lxml2 -F/usr/local/Cellar/r/3.2.4_1/R.framework/.. -framework R -lintl -Wl,-framework -Wl,CoreFoundation
    installing to /usr/local/lib/R/3.2/site-library/XML/libs
    ** R
    ** inst
    ** preparing package for lazy loading
    Creating a generic function for ‘source’ from package ‘base’ in package ‘XML’
    in method for ‘xmlAttrsToDataFrame’ with signature ‘"AsIs"’: no definition for class “AsIs”
    in method for ‘readKeyValueDB’ with signature ‘"AsIs"’: no definition for class “AsIs”
    in method for ‘readSolrDoc’ with signature ‘"AsIs"’: no definition for class “AsIs”
    ** help
    *** installing help indices
    ** building package indices
    ** testing if installed package can be loaded
    Error : .onLoad failed in loadNamespace() for 'XML', details:
      call: dyn.load(file, DLLpath = DLLpath, ...)
      error: unable to load shared object '/usr/local/lib/R/3.2/site-library/XML/libs/XML.so':
      dlopen(/usr/local/lib/R/3.2/site-library/XML/libs/XML.so, 6): Library not loaded: libxml2.2.dylib
      Referenced from: /usr/local/lib/R/3.2/site-library/XML/libs/XML.so
      Reason: image not found
    Error: loading failed
    Execution halted
    ERROR: loading failed
    * removing ‘/usr/local/lib/R/3.2/site-library/XML’

    The downloaded source packages are in
        ‘/private/var/folders/jy/0cwn40p951xc7f1480z3sxzm0000gn/T/RtmpEi0XEv/downloaded_packages’
    Warning message:
    In install.packages("XML") :
      installation of package ‘XML’ had non-zero exit status

我通过使用 anaconda 安装 XML 解决了这个问题:

conda install -c r r-xml=3.98_1.5

adding to @Travis's answer using conda install -cr r-xml=3.98_1.5 or conda install -c conda-forge r-xml works.使用conda install -cr r-xml=3.98_1.5conda install -cr r-xml=3.98_1.5 conda install -c conda-forge r-xml conda install -cr r-xml=3.98_1.5添加到conda install -cr r-xml=3.98_1.5的答案中。 But make sure to run conda update r-essentials and reopen/restart the r terminal\\notebook (whichever is your case).但请确保运行conda update r-essentials并重新打开/重新启动r terminal\\notebook (以您的情况为准)。

Solution for Mac OS Catalina (ie in zsh). Mac OS Catalina 的解决方案(即在 zsh 中)。

I'm a novice, but this worked for me.我是新手,但这对我有用。

  1. Make sure you have libxml2 installed in homebrew.确保在自制软件中安装了 libxml2。 (If you got it, brew list | grep libxml2 should confirm it; otherwise install it brew install libxml2 . Don't have homebrew? Install it .) (如果你得到它, brew list | grep libxml2应该确认它;否则安装它brew install libxml2 。没有自制软件?安装它。)

  2. Either create a zsh run com, touch ~/.zshrc , or find it in your home directory cd ~ .创建一个 zsh run com, touch ~/.zshrc ,或者在你的主目录cd ~找到它。 (Use ls -a in Terminal to see if its in ~ .) (在终端中使用ls -a来查看它是否在~ 。)

  3. Then make sure: export PATH="/usr/local/opt/libxml2/bin:$PATH" is in there (ie in ~/.zshrc ).然后确保: export PATH="/usr/local/opt/libxml2/bin:$PATH"在那里(即在~/.zshrc )。 It shouldn't be in there yet!它不应该在那里! Add it using sudo nano ~/.zshrc .使用sudo nano ~/.zshrc添加它。 Then save it (ctrl + x, Y, enter).然后保存(ctrl + x, Y, enter)。 This should make sure the path to brew's libxml2 is the first thing that comes up when looking for libxml2.这应该确保 brew 的 libxml2 的路径是查找 libxml2 时出现的第一件事。 (FYI, I also added it to ~/.zprofile . I don't know which one is correct.) (仅供参考,我也将它添加到~/.zprofile 。我不知道哪个是正确的。)

  4. Ok, now restart your terminal.好的,现在重启你的终端。 Then run R in the Terminal using R .然后使用R在终端中运行R Once R has started, install.packages("XML") , pick a server to download it, and you should be good to go.一旦 R 启动, install.packages("XML") ,选择一个服务器来下载它,你应该很高兴。

You explained what is wrong and that helps.你解释了什么是错的,这有帮助。

XML package documentation in here: https://cran.r-project.org/web/packages/XML/index.html此处的 XML 包文档: https : //cran.r-project.org/web/packages/XML/index.html

Pay attetion to where it says You are trying to use a version 2.* edition of libxml but an incompatible library.注意它说You are trying to use a version 2.* edition of libxml but an incompatible library.

What system are you using?你用的是什么系统? I use OSX and when I had a similar issue I did run我使用 OSX,当我遇到类似问题时,我确实运行了

brew install libxml2

and then it worked然后它起作用了

I also see you use R 3.0+ and that should be very compatible.我还看到您使用 R 3.0+,这应该非常兼容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM