tl;dr Can I configure rpy2 so that it loads the conda installation instead of the system one?
My issue
When I run rpy2
it uses the system installation of R, but it introspects and loads libraries from my conda installation of R.
This has various side effects such as segfaults and so on...
Reproduction
I have an installation of R on a Ubuntu 18 server, that my sysadmin has installed. I want to use conda with python and rpy2 to make sure I can select versions somewhat freely.
Below, you can see I am in a conda environment called (rnvp)
, that rpy2
identifies the 4.0.5 conda installation of R, but that the rpy2.robjects
library loads the system R installation instead, which is 4.0.3.
When running the situation
script, I get the below
(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
During startup - Warning messages:
1: package ‘methods’ was built under R version 4.0.5
2: package ‘datasets’ was built under R version 4.0.5
3: package ‘utils’ was built under R version 4.0.5
4: package ‘grDevices’ was built under R version 4.0.5
5: package ‘graphics’ was built under R version 4.0.5
6: package ‘stats’ was built under R version 4.0.5
>>> print(ro.r)
<rpy2.robjects.R object at 0x7f8f16ece8b0>
platform: x86_64-pc-linux-gnu
arch: x86_64
os: linux-gnu
system: x86_64, linux-gnu
status:
major: 4
minor: 0.3
year: 2020
month: 10
day: 10
svn rev: 79318
language: R
version.string: R version 4.0.3 (2020-10-10)
nickname: Bunny-Wunnies Freak Out
>>> import rpy2.situation
>>> for row in rpy2.situation.iter_info():
... print(row)
...
rpy2 version:
3.4.5
Python version:
3.9.6 (default, Aug 18 2021, 19:38:01)
[GCC 7.5.0]
Looking for R's HOME:
Environment variable R_HOME: /home/ludhu126/miniconda3/envs/rnvp/lib/R
Calling `R RHOME`: /home/ludhu126/miniconda3/envs/rnvp/lib/R
Environment variable R_LIBS_USER: None
R's additions to LD_LIBRARY_PATH:
R version:
In the PATH: R version 4.0.5 (2021-03-31) -- "Shake and Throw"
Loading R library from rpy2: OK
Additional directories to load R packages from:
None
C extension compilation:
include:
['/home/ludhu126/miniconda3/envs/rnvp/lib/R/include']
libraries:
['R', 'pcre2-8', 'lzma', 'bz2', 'z', 'rt', 'dl', 'm', 'iconv', 'icuuc', 'icui18n']
library_dirs:
['/home/ludhu126/miniconda3/envs/rnvp/lib', '/home/ludhu126/miniconda3/envs/rnvp/lib/R/lib', '/home/ludhu126/miniconda3/envs/rnvp/lib']
extra_compile_args:
[]
extra_link_args:
['-Wl,--export-dynamic', '-fopenmp', '-Wl,-O2', '-Wl,--sort-common', '-Wl,--as-needed', '-Wl,-z,relro', '-Wl,-z,now', '-Wl,--disable-new-dtags', '-Wl,--gc-sections', '-Wl,-rpath,/home/ludhu126/miniconda3/envs/rnvp/lib', '-Wl,-rpath-link,/home/ludhu126/miniconda3/envs/rnvp/lib']
The terminal points to the conda installation of R, which indeed is 4.0.5
(rnvp) ludhu126@hyperion:~/real-nvp/real-nvp$ which R
/home/ludhu126/miniconda3/envs/rnvp/bin/R
(rnvp) ludhu126@hyperion:~/real-nvp/real-nvp$ R --version
R version 4.0.5 (2021-03-31) -- "Shake and Throw"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-conda-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.
Outside this environment, I have R 4.0.3 from /usr/lib/R
(rnvp) ludhu126@hyperion:~/real-nvp/real-nvp$ conda activate base
(base) ludhu126@hyperion:~/real-nvp/real-nvp$ which R
/usr/bin/R
(base) ludhu126@hyperion:~/real-nvp/real-nvp$ R --version
R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.
Question Can I configure rpy2 so that it loads the conda installation instead?
Close duplicates
- How to install rpy2 via conda using default R installation wants to use the local installation instead of the conda installation. it is also for python version 2.7
- Install and use RPy2 (using conda) so that it uses default R installation in /usr/lib/R R mentions other problems, such as not installing rpy2 at all, problems binding to lapack dlls, or not setting up the R_HOME variable. All these things are no problem for me.
- How to point rpy2 to existing R installation? says that PATH is used to resolve the R installation. but my
which R
above suggests that is not a problem. - force rpy2 in conda environment to use the R outside of the conda environment is about loading the wrong R libraries. but that is fine - it loads the conda R installation libraries as desired.
- Getting Segmentation fault Core dumped error while importing robjects from rpy2 suggests uninstalling the base R installation. I am not sysadmin and cannot do that.