安装并使用RPy2(使用conda),以便它在/ usr / lib / R R中使用默认的R安装。 [英] Install and use RPy2 (using conda) so that it uses default R installation in /usr/lib/R R

查看:557
本文介绍了安装并使用RPy2(使用conda),以便它在/ usr / lib / R R中使用默认的R安装。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用RPy2从Python的R包中调用函数。我使用conda安装了RPy2,并意识到它在conda内安装了R的新副本...我不想要那样。我只想拥有一个R,并在/ usr / lib / R中使用默认的R。

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.

该怎么做?如何强制conda以及Python和RPy2使用/ usr / lib / R中安装的默认R?

How to do that? How to force conda and Python and RPy2 to use default R installed in /usr/lib/R?

推荐答案

conda instal 安装rpy2,只需使用 pip install rpy2 。以下是您可能需要在rpy2之前安装的一些其他软件包:

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

一些注意事项:


  1. pip 应该指向anaconda路径的

  2. 在安装 rpy2

  3. 之后,应正确设置R的环境变量(R_HOME和PATH)。 ,调用 import rpy2.robjects作为robjects

  1. The which pip should refer to anaconda's path
  2. The environment variable for R (R_HOME and PATH) should be properly set up before you install the rpy2
  3. After the installation, you may encounter an error when calling import rpy2.robjects as robjects:

RRuntimeWarning:错误:包或名称空间时,您可能会遇到错误dyn.load(文件,DLLpath = DLLpath,...)中的 stats加载失败:
无法加载共享对象 /usr/local/lib/R/library/stats/libs/stats.so ':
libRlapack.so:无法打开共享的对象文件:无此类文件或目录

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

为此,我在我如何解决该错误-libRlapack.so:无法打开共享对象文件:没有这样的文件或目录

您需要找到您的 libRlapack.so 文件(在我的情况下,该文件位于 / usr / local / lib / R / lib / ),或以下命令应显示此文件的路径:

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

,然后编写此路径到 /etc/ld.so.conf.d/libR.conf ,然后运行 ldconfig

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

这应该可以解决问题。

这篇关于安装并使用RPy2(使用conda),以便它在/ usr / lib / R R中使用默认的R安装。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆