Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Segmentation fault Core dumped error while importing robjects from rpy2

Tags:

python

r

rpy2

Installed R and rpy2 manually

Installation is successful but getting the above mentioned error. Please help me out?

Outputs of some useful commands:

>>> import rpy2
>>> rpy2.__path__
['/home/ashish/miniconda2/lib/python2.7/site-packages/rpy2-2.8.2-py2.7-linux-x86_64.egg/rpy2']
>>> import rpy2.robjects
cannot find system Renviron
/home/ashish/miniconda2/lib/python2.7/site-packages/rpy2-2.8.2-py2.7-linux- x86_64.egg/rpy2/rinterface/__init__.py:185: RRuntimeWarning: Fatal error: unable to open the base package


warnings.warn(x, RRuntimeWarning)
Segmentation fault (core dumped)

Thanks in advance..

like image 917
Sahil Thakur Avatar asked Sep 06 '16 11:09

Sahil Thakur


People also ask

Why am I getting segmentation fault core dumped?

Core Dump/Segmentation fault is a specific kind of error caused by accessing memory that “does not belong to you.” When a piece of code tries to do read and write operation in a read only location in memory or freed block of memory, it is known as core dump. It is an error indicating memory corruption.

What does zsh segmentation fault mean?

A segmentation fault (aka segfault) is a common condition that causes programs to crash; they are often associated with a file named core . Segfaults are caused by a program trying to read or write an illegal memory location.

What happens segfault?

A segmentation fault occurs when a program attempts to access a memory location that it is not allowed to access, or attempts to access a memory location in a way that is not allowed (for example, attempting to write to a read-only location, or to overwrite part of the operating system).


1 Answers

If you install rpy2 via conda, and also have a system installation of R on the same machine (e.g with RStudio), the system's R installation will be used. Since this R version doesn't match the one that rpy2 needs, segmentation faults occur.

1) remove any existing system installations of R (see here). Verify that you don't have any installations of R:

$>which R
R not found

2) define R_HOME env variable, either in your .rc file:

export R_HOME=/Users/<your user>/anaconda3/envs/<env name>/lib/R

or dynamically in the python project:

import os
os.environ['R_HOME'] = '/Users/<your user>/anaconda3/envs/<env name>/lib/R'
like image 133
Eitan Rousso Avatar answered Sep 21 '22 22:09

Eitan Rousso