I am having problems importing rpy2 in a Jupyter notebook using Mac M1. It doesn't seem that there is an issue if I run the code using python from the terminal. I am aware that many are having issues as well, for example this issue on github, this question on installing rpy2, issues with Windows, etc.
I have tried many things but none seem to work. My error message is also slightly different.
In sum, when I import from rpy2.robjects.packages import importr
, I get the errors:
Unable to determine R library path: Command '('/Users/mydir/miniconda3/envs/ds_project/lib/R/bin/Rscript', '-e', 'cat(Sys.getenv("LD_LIBRARY_PATH"))')' died with <Signals.SIGABRT: 6>.
followed by
OSError: cannot load library '/Users/mydir/miniconda3/envs/ds_project/lib/R/lib/libR.dylib': dlopen(/Users/mydir/miniconda3/envs/ds_project/lib/R/lib/libR.dylib, 0x0002): Library not loaded: '@rpath/libblas.3.dylib'
Referenced from: '/Users/mydir/miniconda3/envs/ds_project/lib/R/lib/libR.dylib'
Reason: tried: '/Users/mydir/miniconda3/envs/ds_project/lib/R/lib/libblas.3.dylib' (no such file), '/Users/mydir/miniconda3/envs/ds_project/lib/R/lib/../../libblas.3.dylib' (no such file), '/Users/mydir/miniconda3/envs/ds_project/lib/R/lib/libblas.3.dylib' (no such file), '/Users/mydir/miniconda3/envs/ds_project/lib/R/lib/../../libblas.3.dylib' (no such file), '/Users/mydir/miniconda3/envs/ds_project/lib/python3.11/site-packages/../../libblas.3.dylib' (no such file), '/Users/mydir/miniconda3/envs/ds_project/bin/../lib/libblas.3.dylib' (no such file), '/usr/local/lib/libblas.3.dylib' (no such file), '/usr/lib/libblas.3.dylib' (no such file)
In the issue raised in the GitHub link, their error message was related to the compatibility issue of using the intel-based R vs m1 chip-based R. I don't get that error here.
I have tried installing r-base
, r-essentials
via conda as people have pointed out but it still doesn't work.
I also tried setting the R-path, based on the error message, as:
import os
os.environ['R_HOME'] = '/Users/mydir/miniconda3/envs/ds_project/lib/R/'
but it still complains.
I find the error message strange given that the path
/Users/mydir/miniconda3/envs/ds_project/lib/R/bin/Rscript
exists on my local machine.
Could this be an issue with my IDE, Vscode? Or with Jupyter notebook (My jupyterlab version is 3.6.5)? As mentioned above, I don't run into problems running this on python on the terminal. My R installation is also located in
/opt/R/arm64/
but I have
/opt/R/x86_64/
available as well.
I would greatly appreciate any help/suggestions. Thank you so much.