草庐IT

r - 无法在 R/RStudio 中安装 XML 包

coder 2024-06-29 原文

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

请注意,这不是 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’

好的 - 所以我通过 Homebrew 软件和强制链接安装了 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 放在那里),我甚至将其符号链接(symbolic link)到 /usr/local/opt/libxml2/include/parser.h,但无济于事。

所以我几乎不知道如何让 RStudio 识别库 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

最佳答案

(当然,我发帖后马上就找到了答案。:)

解决办法是去掉

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

来自 ~/.Renviron 并添加

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

这允许 XML 包编译和安装。

关于r - 无法在 R/RStudio 中安装 XML 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47540782/

有关r - 无法在 R/RStudio 中安装 XML 包的更多相关文章

  1. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  2. ruby-on-rails - 如何从 format.xml 中删除 <hash></hash> - 2

    我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为

  3. ruby-on-rails - 无法使用 Rails 3.2 创建插件? - 2

    我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby​​1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在

  4. ruby - 无法运行 Rails 2.x 应用程序 - 2

    我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby​​:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r

  5. ruby-on-rails - 无法在centos上安装therubyracer(V8和GCC出错) - 2

    我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e

  6. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

  7. ruby - 无法覆盖 irb 中的 to_s - 2

    我在pry中定义了一个函数:to_s,但我无法调用它。这个方法去哪里了,怎么调用?pry(main)>defto_spry(main)*'hello'pry(main)*endpry(main)>to_s=>"main"我的ruby版本是2.1.2看了一些答案和搜索后,我认为我得到了正确的答案:这个方法用在什么地方?在irb或pry中定义方法时,会转到Object.instance_methods[1]pry(main)>defto_s[1]pry(main)*'hello'[1]pry(main)*end=>:to_s[2]pry(main)>defhello[2]pry(main)

  8. ruby - 无法在 60 秒内获得稳定的 Firefox 连接 (127.0.0.1 :7055) - 2

    我使用的是Firefox版本36.0.1和Selenium-Webdrivergem版本2.45.0。我能够创建Firefox实例,但无法使用脚本继续进行进一步的操作无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055)错误。有人能帮帮我吗? 最佳答案 我遇到了同样的问题。降级到firefoxv33后一切正常。您可以找到旧版本here 关于ruby-无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055),我们在StackOverflow上找到一个类

  9. ruby - 安装 Ruby 时遇到问题(无法下载资源 "readline--patch") - 2

    当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub

  10. ruby-on-rails - 无法让 rspec、spork 和调试器正常运行 - 2

    GivenIamadumbprogrammerandIamusingrspecandIamusingsporkandIwanttodebug...mmm...let'ssaaay,aspecforPhone.那么,我应该把“require'ruby-debug'”行放在哪里,以便在phone_spec.rb的特定点停止处理?(我所要求的只是一个大而粗的箭头,即使是一个有挑战性的程序员也能看到:-3)我已经尝试了很多位置,除非我没有正确测试它们,否则会发生一些奇怪的事情:在spec_helper.rb中的以下位置:require'rubygems'require'spork'

随机推荐