【问题标题】:Cannot install XML package in R/RStudio无法在 R/RStudio 中安装 XML 包
【发布时间】:2017-11-28 20:56:41
【问题描述】:

[环境:macOS 10.12.6、RStudio 1.1.383、R 3.4.2(通过自制软件)]

请注意,这不是this question 的重复 - 那里的解决方案对我不起作用。

当我尝试在 RStudio 中安装 XML 包时出现安装错误:

> install.packages("XML")
Installing package into ‘/usr/local/lib/R/3.4/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/XML_3.98-1.9.tar.gz'
Content type 'application/x-gzip' length 1599437 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/bin/sed
checking for pkg-config... /usr/local/bin/pkg-config
checking for xml2-config... /usr/bin/xml2-config
USE_XML2 = yes
SED_EXTENDED_ARG: -E
Minor 9, Patch 4 for 2.9.4
Located parser file -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/libxml2/parser.h
Checking for 1.8:  -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/libxml2
Using libxml2.*
checking for gzopen in -lz... yes
checking for xmlParseFile in -lxml2... no
checking for xmlParseFile in -lxml... no
configure: error: "libxml not found"
ERROR: configuration failed for package ‘XML’
* removing ‘/usr/local/lib/R/3.4/site-library/XML’

好的 - 所以我通过自制软件安装了 libxml2 (2.9.7) 并强制链接:

>brew install libxml2
>brew link libxml2 --force

我将此代码添加到~/.Renviron

LIBXML_INCDIR=/usr/local/opt/libxml2
LIBXML_LIBDIR=/usr/local/opt/libxml2
PKG_CONFIG_PATH=/usr/local/opt/libxml2/lib/pkgconfig
LDFLAGS=-L/usr/local/opt/libxml2/lib
CPPFLAGS=-I/usr/local/opt/libxml2/include

我退出并重新启动 RStudio;再试一次:

> install.packages("XML")
Installing package into ‘/usr/local/lib/R/3.4/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/XML_3.98-1.9.tar.gz'
Content type 'application/x-gzip' length 1599437 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/bin/sed
checking for pkg-config... /usr/local/bin/pkg-config
Checking directory of LIBXML_INCDIR
You specified LIBXML_INCDIR, but we couldn't find parser.h
Please specify it correctly and re-run the INSTALL'ation.
ERROR: configuration failed for package ‘XML’
* removing ‘/usr/local/lib/R/3.4/site-library/XML’

parser.h 确实存在于/usr/local/opt/libxml2/include/libxml2/libxml/parser.h(由 brew 放置在那里),我什至将其符号链接到 /usr/local/opt/libxml2/include/parser.h,但无济于事。

所以我几乎不知道如何让 RStudio 识别 lib libxml2parser.h

RStudio 环境:

> Sys.getenv()
__CF_USER_TEXT_ENCODING    0x535:0x0:0x0
Apple_PubSub_Socket_Render
                           /private/tmp/com.apple.launchd.oqvtmxMkmV/Render
CLICOLOR_FORCE             1
CPPFLAGS                   -I/usr/local/opt/libxml2/include
DISPLAY                    /private/tmp/com.apple.launchd.z0UbJdCqkr/org.macosforge.xquartz:0
DYLD_FALLBACK_LIBRARY_PATH
                           /usr/local/Cellar/r/3.4.2/lib/R/lib:/Users/conrad/lib:/usr/local/lib:/usr/lib:::/lib
EDITOR                     vi
GIT_ASKPASS                rpostback-askpass
HOME                       /Users/conrad
LANG                       en_US.UTF-8
LC_CTYPE                   en_US.UTF-8
LDFLAGS                    -L/usr/local/opt/libxml2/lib
LIBXML_INCDIR              /usr/local/opt/libxml2
LIBXML_LIBDIR              /usr/local/opt/libxml2
LN_S                       ln -s
LOGNAME                    conrad
MAKE                       make
PAGER                      /usr/bin/less
PATH                       /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/MacGPG2/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
PKG_CONFIG_PATH            /usr/local/opt/libxml2/lib/pkgconfig
R_BROWSER                  /usr/bin/open
R_BZIPCMD                  /usr/bin/bzip2
R_DOC_DIR                  /usr/local/Cellar/r/3.4.2/lib/R/doc
R_GZIPCMD                  /usr/bin/gzip
R_HOME                     /usr/local/Cellar/r/3.4.2/lib/R
R_INCLUDE_DIR              /usr/local/Cellar/r/3.4.2/lib/R/include
R_LIBS_SITE                
R_LIBS_USER                ~/Library/R/3.4/library
R_PAPERSIZE                a4
R_PDFVIEWER                /usr/bin/open
R_PLATFORM                 x86_64-apple-darwin16.7.0
R_PRINTCMD                 lpr
R_RD4PDF                   times,inconsolata,hyper
R_SESSION_TMPDIR           /var/folders/dr/ldgx2z697jv6b0b281qjcsw400019n/T//RtmpvNqwQA
R_SHARE_DIR                /usr/local/Cellar/r/3.4.2/lib/R/share
R_SYSTEM_ABI               osx,gcc,gxx,gfortran,?
R_TEXI2DVICMD              /usr/bin/texi2dvi
R_UNZIPCMD                 /usr/bin/unzip
R_ZIPCMD                   /usr/bin/zip
RMARKDOWN_MATHJAX_PATH     /Applications/RStudio.app/Contents/Resources/resources/mathjax-26
RS_RPOSTBACK_PATH          /Applications/RStudio.app/Contents/MacOS/rpostback
RS_SHARED_SECRET           <redacted>
RSTUDIO                    1
RSTUDIO_CONSOLE_COLOR      256
RSTUDIO_CONSOLE_WIDTH      91
RSTUDIO_PANDOC             /Applications/RStudio.app/Contents/MacOS/pandoc
RSTUDIO_SESSION_PORT       9090
RSTUDIO_USER_IDENTITY      conrad
RSTUDIO_WINUTILS           bin/winutils
SED                        /usr/bin/sed
SHELL                      /bin/tcsh
SSH_ASKPASS                rpostback-askpass
SSH_AUTH_SOCK              /private/tmp/com.apple.launchd.wBdDUnzsja/Listeners
TAR                        /usr/bin/tar
TERM                       xterm-256color
TMPDIR                     /var/folders/dr/ldgx2z697jv6b0b281qjcsw400019n/T/
USER                       conrad
XPC_FLAGS                  0x0
XPC_SERVICE_NAME           0

【问题讨论】:

    标签: r xml rstudio homebrew libxml2


    【解决方案1】:

    (当然,我在发布后立即发现了答案。:)

    解决办法是去掉

    LIBXML_INCDIR=/usr/local/opt/libxml2
    LIBXML_LIBDIR=/usr/local/opt/libxml2
    

    来自~/.Renviron 并添加

    XML_CONFIG=/usr/local/bin/xml2-config
    

    这允许 XML 包编译和安装。

    【讨论】:

    • 那么你到底在哪里运行呢?
    • @BonnieB 你不要“运行”这些语句 - 文本文件 ~/.Renviron 需要用你最喜欢的编辑器(TextEdit.app、emacs 等)编辑并添加/删除必要的行.原始问题中的安装命令发生在 RStudio 中的命令提示符处。
    • 公平 - 谢谢!我需要 XML,因为它是 R 中 tmap 库的依赖项。最后,在 R 版本 3.5.2 中对我有用的是安装 tmaptools。希望这对某人有用。
    • 对于由 Homebrew 安装的 libxml2,我使用了:export XML_CONFIG=/usr/local/Cellar//libxml2/2.9.10_1/bin/xml2-config,它成功了。
    【解决方案2】:

    请设置PKG_CONFIG_PATH,它应该包含一个libxml-2.0.pc文件。 对我来说,我通过 brew 安装了 libxml2,并且这段代码有效:

    export PKG_CONFIG_PATH="/usr/local/Cellar/libxml2/2.9.8/lib/pkgconfig"
    

    【讨论】:

      【解决方案3】:

      我有这个问题很长时间了。仅在 RStudio 中。在 R 和库上安装包。转到 RStudio 并要求该软件包。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-12-24
        • 1970-01-01
        • 2020-08-13
        • 1970-01-01
        • 2022-07-04
        • 1970-01-01
        • 2015-05-14
        相关资源
        最近更新 更多