R fails after installing GTK and RGtk2

时光毁灭记忆、已成空白 提交于 2019-11-28 05:04:02

I too had this problem. Here is how I worked around it using macports gtk2 -- not the http://r.research.att.com/ version. This was with R version 3.0.1 (2013-05-16) -- "Good Sport", also compiled from source.

install gtk2

sudo port install gtk2 ## (X11 -- not aqua)

configure

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

then install

I downloaded RGtk2 and cairoDevice from CRAN and did source install:

R CMD INSTALL RGtk2
R CMD INSTALL cairoDevice

In addition to jverzani's answer, if you want to use Homebrew:

brew install gtk+
export PKG_CONFIG_PATH=/usr/X11/lib/pkgconfig:$PKG_CONFIG_PATH

and then install RGtk2 and cairoDevice from source.

I used the Homebrew solution (suggested by masaha03) on Snow Leopard and still had crashing problems with R. It turned out that in such a configuration, gtk is using cairo installed by homebrew whereas RGtk2 and cairoDevice are using the native cairo installation which is a different version. Since cairo and other dependent libraries are "keg-only" I needed to force a symlink for those:

brew link --force cairo
brew link --force pixman

These two were sufficient for me but there might be others that need to be linked. The reason is that the Homebrew cairo might be dependent on a specific version of a library, but the system version of that library might be lower. In such a case, the installation of RGtk2 fails with a message that gtk+ is not installed.

Lastly, the PKG_CONFIG_PATH has to point to the Homebrew packages first and then to the native ones:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig:$PKG_CONFIG_PATH

Then install RGtk2 and cairoDevice.

On a MAC when working with R I try to follow the principle of trying to do everything natively and avoid Homebrew and Macports solutions. Even though for other uses I love homebrew.

I will just reiterate the suggestion by @BondedDust to use Simon Urbanek's advice.

Step 1: Download the library from http://r.research.att.com/#other

Step 2: Just verify where this GTK+ framework is now installed on your computer---on mine it was installed at:
/Library/Frameworks/GTK+.framework/

Step 3: Find the sub-directory where the newly installed GTK+'s pkg-config file is placed. In my case:
Versions/2.24.X11/Resources/lib/pkgconfig

Step 4: Make sure this is in your PKG_CONFIG_PATH variable. In my case I just set the variable in R directly before installing the RGtk2 package from source as follows:
Sys.setenv(PKG_CONFIG_PATH= "/Library/Frameworks/GTK+.framework/Versions/2.24.X11/Resources/lib/pkgconfig")
install.packages("RGtk2", type="source")

NOTE: my PKG_CONFIG_PATH was previously empty so I didn't need to concatenate to the old value, but if that is not the case for you it is easy to use Sys.getenv to get the old value and append that if necessary.

I want to thank all the people that contributed to a solution of this problem. Eventually I managed to fix it, after numerous trials (and late nights!). The basic methods that have been proposed are:

  • install GTk+ and cairo with homebrew

  • install GTk2 and cairo with macports

I never managed to make this work with macports, but eventually I've been successful with homebrew, after many fruitless attempts. I cleaned up my PATH that was getting a bit messy. Then I basically uninstalled X11, GTk+, cairo and all their dependencies.

I've first installed XQuartz-2.7.4.

For the installation of all the needed components I've followed the instructions found here and installed yarp using homebrew and the associated instructions. Most people may found this bizarre (I did), but installing yarp installed sequentially all the needed dependencies to make GTk+ work (obviously I tried just to install GTk+ and cairo but it never worked or eventually RGTk2 failed to compile).

I then installed (using R CMD INSTALL) GTk2, Cairo, cairoDevice and rattle from sources. After so many months trying to fix the problem I couldn't believe that everything worked!

Thanks again to all those that contributed with their effort and their research to fix the problem.

Enzo

Update: as far as I can tell, this problem still persists (R version 3.1.0) but the information provided by people in this thread still does the trick for working around it. I ended up running through the installation many times on different Mac OS X systems in the last couple of months and ended up throwing the info together for people new to R (basically a little more detailed version of John Verzani's answer, aimed at Mac OS X > 10.7). It's worked well so far so at the chance of being useful to others I wanted to post the link:

Working around GTK trouble on R > 3.0

smci

jverzani's answer is very useful, here are some further issues I found, I edited on to his post:

  1. Installing gtk2: definitely use macports gtk2. Don't contemplate building gtk2 yourself from source.

    sudo port install gtk2 +x11 ## (+x11, not +quartz/ +universal/ +no_x11)

  2. Which variant of gtk2 and its dependencies to install: Do not install the +quartz variant, use the +x11 variant, even if (as with all Mac OS 10.8.x+) you have XQuartz and not X11 installed per Brandon Allbery's useful post to macports-users explaining the +quartz variant name is a misnomer.

    2b. If you accidentally end up selecting anything other than +x11 variant for gtk2 and/or any of its variants (atk, cairo, pango, etc.) you will get compile fails on gtk2. Example: atk was failing for me with compile error on /opt/local/include/atk-1.0/atk/atk.h . You must both delete the wrong installed variants: e.g. sudo port uninstall --follow-dependents cairo @1.12.14_0+quartz+x11 and also clean the unwantedly selected variants with sudo port clean atk cairo pango ...

  3. Then as jverzani notes notes you need a source install (not the MacOS binary install) of these:

    ...#then install: download RGtk2 and cairoDevice from CRAN and do source install:

    R CMD INSTALL RGtk2

    R CMD INSTALL cairoDevice

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!