Segmentation Fault 11 on Mac OS X (Mountain Lion) when importing rpy2.robjects

Issue #214 closed
Philip Jones
created an issue

I'm running Mountain Lion which has Python 2.7.2 installed by default. I've installed Python 2.7.8 from .dmg at python.org and I've installed the latest version of R (v 3.1.1). I've set up a new Python environment using both versions of Python. I can install packages using pip install such as numpy, matplotlib, ipython, and a few others. When I start up Python in the terminal, I can import all the installed packages (e.g. numpy, matplotlib, etc.) and there are no problems. But when I enter either:

import rpy2.robjects as objects

and then exit() from Python, there is a segmentation fault 11 reported. This also happens with:

import pandas.rpy.common as com

The version of pandas that is installed is 0.14.1 (but the same problem occurred with previous version 0.14.0).

I've tried reinstalling R and recreating new virtual environments with new installations of all the packages but problem persists.

Comments (25)

  1. Laurent Gautier

    I don't have access to an OS X machine on which I could do rpy2 development, but with your help we might be able to figure this out.

    Does the following run ?

    # run this before anything else in a Python session
    import rpy2.rinterface as ri
    ri.initr()
    

    In a terminal what is the output of

    python -m rpy2.tests
    

    ?

  2. Philip Jones reporter

    Hi Laurent

    Thanks very much for your help.

    The first bit:

    import.rpy2.rinterface as ri
    ri.initr()

    …seems to run OK but when I exit Python, it gives a segmentation fault 11. This is what was happening with my original set up. I could, probably go on and use the system, inputting commands one at a time at the terminal. However, when trying to run Python scripts, that is where is all falls apart because the Segmentation fault 11 seems to cause the scripts to die.

    When entering the second command at the Terminal prompt:

    $ env/bin/python -m rpy2.tests

    R starts up and I then get the following output:

    ..................................................................................................................................................................................................................x..................................................................................................................................................s......s.....

  3. Laurent Gautier

    Ok. The segfault when exiting after only lower-level interface initialized means something relatively basic is going on. Since I have not seen a lot of reports about similar problems on OS X 10.9 (so far the biggest problem appears to be around building with an homebrew R - see #194), the issue might be local to your system.

    When running env/bin/python -m rpy2.tests, the first lines should report the version of R rpy2 was built against, and the version of rpy2 picked up at run time. Do the versions of R match ? (and would you be able to share these lines ?). Does running the tests end with segfault as well ?

  4. Philip Jones reporter

    Yes, they seem to match. I've edited my .Rprofile so when R starts up I get a few reminders about various bit and pieces (which, to avoid confusion, I hadn't included in the output) but, in amongst that, there was the following line:

    rpy2 version: 2.4.2
    - built against R version: 3-1.1--66115
    - running linked to R version: R version 3.1.1 (2014-07-10)
    .....Loading required package: stats
    

    The Segmentation Fault: 11 was also reported immediately after the results of the tests which doesn't seem to be included in my above response for some reason. The exact output from the tests was:

    $ env/bin/python -m rpy2.tests
    

    R starts up and I then get the following output:

    ..................................................................................................................................................................................................................x..................................................................................................................................................s......s.....
    ----------------------------------------------------------------------
    Ran 375 tests in 4.936s
    
    OK (skipped=2, expected failures=1)
    Segmentation fault: 11
    

    P.S. I'm using MacOSX 10.8 (rather than 10.9).

  5. rohitx

    I have the same problem with newer version of MacOs. Relevant information:

    MacOS: 10.11.6
    ipython: 5.0.0
    rpy2: 2.8.2
    

    I tried the following:

    In [1]: import rpy2
    
    In [2]: import rpy2.robjects as robj
    Segmentation fault: 11
    

    And this:

    In [1]: import rpy2.rinterface as ri
    
    In [2]: ri.initr()
    Segmentation fault: 11
    

    and this:

    $ python -m rpy2.tests
    Segmentation fault: 11
    

    I have installed ipython using Homebrew. Any ideas? Thanks!

  6. Laurent Gautier

    I still don't have access to an OS X machine for dev work on rpy2, so we will have to guess a little.

    Is the version of R rpy2 is built again corresponding to what you'd expect ?

    import ryp2.rinterface as ri
    print('.'.join(ri.R_VERSION_BUILD[:2]))
    
  7. Laurent Gautier

    To my knowledge, rpy2 does not involve any Tk. However, R may have been built with bindings to it. The issue might then have to do with how you got R on your machine (how R was built).

  8. rohitx

    I installed R by downloading the R dmg file from CRAN. I needed that in order to install RStudio. I am downloading R executable right now as we speak. I will try reinstalling R and see if the problem persists. Will report shortly.

  9. rohitx

    I do not have anaconda on my machine. I use Homebrew. Sweet, at least I am able to import rpy2.objects without segmentation fault. Reinstalling R worked!

    Thank you Laurent for all your help. I wonder what caused the segmentation fault but things now work just fine.

  10. Laurent Gautier

    Ah. At least someone on the thread had anaconda and I assumed that it was common to all.

    Good that you solved it. R's shared C library can change across R versions, breaking the C-written bridge in rpy2. Reinstalling R (and/or rpy2) generally solves the issue.

  11. Sabine Bellstedt

    I've been having essentially this exact issue for a while without being able to solve it. I successfully use rpy2 on my desktop, but the same installation runs into errors on my laptop.

    The laptop has OS 10.12.6, operating on python 2.7.13. I've installed version 2.2.1 of rpy2 (the same version I have running on my desktop), after running into some issues during the installation itself (see thread here in which we problemsolve: https://github.com/swincas/code-review/issues/15)

    I also run into the issue that whenimport rpy2.rinterface is called, I get segmentation fault: 11. I've tried reinstalling R through Anaconda, but that doesn't seem to have done the trick...

  12. Sabine Bellstedt

    I have since solved this problem! In the end, it was a careful combination of not only reinstalling R through conda, but also reinstalling rpy2 through conda. The version of rpy2 installed this way was 2.8.6, which may have helped a part of the problem.

  13. Eitan Rousso

    The Issue still reproduces.

    Running from rpy2.robjects import pandas2ri causes PyCharm to quit with the message: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

    Running the same code in a Jupyter Notebook causes the kernel to die.

    macOS High Sierra 10.13.6

    installed in a conda environment (through conda-forge channel, in the order below):

    r version 3.5.1
    rpy2 version 2.9.4
    python version is 3.7.1

    running this snippet gives 3.5.1

    I suggest reopening the issue.
    @Laurent Gautier any ideas?

  14. Log in to comment