Getting Segmentation Fault Core Dumped Error While Importing Robjects from Rpy2

Error: Segmentation fault (core dumped)

"Segmentation fault (core dumped)" is the string that Linux prints when a program exits with a SIGSEGV signal and you have core creation enabled. This means some program has crashed.

If you're actually getting this error from running Python, this means the Python interpreter has crashed. There are only a few reasons this can happen:

  1. You're using a third-party extension module written in C, and that extension module has crashed.

  2. You're (directly or indirectly) using the built-in module ctypes, and calling external code that crashes.

  3. There's something wrong with your Python installation.

  4. You've discovered a bug in Python that you should report.

The first is by far the most common. If your q is an instance of some object from some third-party extension module, you may want to look at the documentation.

Often, when C modules crash, it's because you're doing something which is invalid, or at least uncommon and untested. But whether it's your "fault" in that sense or not - that doesn't matter. The module should raise a Python exception that you can debug, instead of crashing. So, you should probably report a bug to whoever wrote the extension. But meanwhile, rather than waiting 6 months for the bug to be fixed and a new version to come out, you need to figure out what you did that triggered the crash, and whether there's some different way to do what you want. Or switch to a different library.

On the other hand, since you're reading and printing out data from somewhere else, it's possible that your Python interpreter just read the line "Segmentation fault (core dumped)" and faithfully printed what it read. In that case, some other program upstream presumably crashed. (It's even possible that nobody crashed—if you fetched this page from the web and printed it out, you'd get that same line, right?) In your case, based on your comment, it's probably the Java program that crashed.

If you're not sure which case it is (and don't want to learn how to do process management, core-file inspection, or C-level debugging today), there's an easy way to test: After print line add a line saying print "And I'm OK". If you see that after the Segmentation fault line, then Python didn't crash, someone else did. If you don't see it, then it's probably Python that's crashed.

How to select R installation when using rpy2 on conda?

Recompile rpy2 locally, with a linker flag to explicate which R library to link to.

Inspired by the blog post https://thomas-cokelaer.info/blog/2012/01/installing-rpy2-with-different-r-version-already-installed/ I decided to recompile rpy2 from source, and supply the R path as an environment variable to the compilation.

(rnvp) ludhu126@hyperion:~/real-nvp/real-nvp$ export LDFLAGS="-Wl,-rpath,/home/ludhu126/miniconda3/envs/rnvp/lib/R/lib"
(rnvp) ludhu126@hyperion:~/real-nvp/real-nvp$ pip install rpy2 --force-reinstall --compile --no-binary rpy2
Collecting rpy2
Using cached rpy2-3.4.5.tar.gz (194 kB)
Collecting cffi>=1.10.0
Using cached cffi-1.14.6-cp39-cp39-manylinux1_x86_64.whl (405 kB)
Collecting jinja2
Using cached Jinja2-3.0.1-py3-none-any.whl (133 kB)
Collecting pytz
Using cached pytz-2021.1-py2.py3-none-any.whl (510 kB)
Collecting tzlocal
Using cached tzlocal-3.0-py3-none-any.whl (16 kB)
Collecting pycparser
Using cached pycparser-2.20-py2.py3-none-any.whl (112 kB)
Collecting MarkupSafe>=2.0
Using cached MarkupSafe-2.0.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (30 kB)
Skipping wheel build for rpy2, due to binaries being disabled for it.
Installing collected packages: pycparser, MarkupSafe, tzlocal, pytz, jinja2, cffi, rpy2
Attempting uninstall: pycparser
Found existing installation: pycparser 2.20
Uninstalling pycparser-2.20:
Successfully uninstalled pycparser-2.20
Attempting uninstall: MarkupSafe
Found existing installation: MarkupSafe 2.0.1
Uninstalling MarkupSafe-2.0.1:
Successfully uninstalled MarkupSafe-2.0.1
Attempting uninstall: tzlocal
Found existing installation: tzlocal 3.0
Uninstalling tzlocal-3.0:
Successfully uninstalled tzlocal-3.0
Attempting uninstall: pytz
Found existing installation: pytz 2021.1
Uninstalling pytz-2021.1:
Successfully uninstalled pytz-2021.1
Attempting uninstall: jinja2
Found existing installation: Jinja2 3.0.1
Uninstalling Jinja2-3.0.1:
Successfully uninstalled Jinja2-3.0.1
Attempting uninstall: cffi
Found existing installation: cffi 1.14.6
Uninstalling cffi-1.14.6:
Successfully uninstalled cffi-1.14.6
Attempting uninstall: rpy2
Found existing installation: rpy2 3.4.5
Uninstalling rpy2-3.4.5:
Successfully uninstalled rpy2-3.4.5
Running setup.py install for rpy2 ... done
Successfully installed MarkupSafe-2.0.1 cffi-1.14.6 jinja2-3.0.1 pycparser-2.20 pytz-2021.1 rpy2-3.4.5 tzlocal-3.0
(rnvp) ludhu126@hyperion:~/real-nvp/real-nvp$ python
Python 3.9.6 (default, Aug 18 2021, 19:38:01)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import rpy2.robjects as ro; print(ro.r('version'))
_
platform x86_64-conda-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 4
minor 0.5
year 2021
month 03
day 31
svn rev 80133
language R
version.string R version 4.0.5 (2021-03-31)
nickname Shake and Throw
>>>


Related Topics



Leave a reply



Submit