问题
I want to call functions from my R packages in Python using RPy2. I installed RPy2 using conda and realized it installed a fresh copy of R inside conda... I don't want that. I just want to have and use one R, the default one in /usr/lib/R.
How to do that? How to force conda and Python and RPy2 to use default R installed in /usr/lib/R?
回答1:
Do not use the conda instal
to install the rpy2, just use the pip install rpy2
. Here are some additional packages you may need to install before the rpy2:
conda install -y PyHamcrest
sudo apt-get install -y libreadline6-dev
pip install rpy2
Some notes:
- The
which pip
should refer to anaconda's path - The environment variable for R (R_HOME and PATH) should be properly set up before you install the
rpy2
After the installation, you may encounter an error when calling
import rpy2.robjects as robjects
:RRuntimeWarning: Error: package or namespace load failed for ‘stats’ in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object '/usr/local/lib/R/library/stats/libs/stats.so': libRlapack.so: cannot open shared object file: No such file or directory
To solve this, I found a solution in How I solved the error - libRlapack.so: cannot open shared object file: No such file or directory
You need to locate your libRlapack.so
file (in my case this file is in /usr/local/lib/R/lib/
), or the following command should show the path to this file:
R CMD ldd /usr/local/lib/R/library/stats/libs/stats.so
and then write this path to the /etc/ld.so.conf.d/libR.conf
and then run ldconfig
:
echo "/usr/local/lib/R/lib/" >> /etc/ld.so.conf.d/libR.conf && ldconfig
That should fix the problem.
来源:https://stackoverflow.com/questions/51486081/install-and-use-rpy2-using-conda-so-that-it-uses-default-r-installation-in-us