简体   繁体   English

在Jupyter Notebook中使用rpy2进行内联rmagic

[英]Using rpy2 for inline rmagic with jupyter notebook

I am trying to use inline rmagic with jupyter notebook, but have had an extremely difficult time trying to get it to work. 我正在尝试将内联rmagic与jupyter笔记本一起使用,但是尝试使其工作非常困难。

Whenever I try to load %load_ext rpy2.ipython , I get the following error: 每当我尝试加载%load_ext rpy2.ipython ,都会出现以下错误:

ImportError: dlopen(/Users/MyName/anaconda/lib/python2.7/site
   packages/rpy2/rinterface/_rinterface.so, 2): Library not loaded: liblzma.5.dylib
   Referenced from: /Users/MyName/anaconda/lib/python2.7/site-
   packages/rpy2/rinterface/_rinterface.so
   Reason: image not found

I have tried installing it with pip , tried installing it with conda install -cr rpy2 . 我尝试使用pip安装它,尝试conda install -cr rpy2安装它。

Beside this rpy2 issue, I was able to set up R and Jupyter notebook so that I can create a new notebook with R, so it doesn't seem to be an R/Jupyter communication issue. 除了这个rpy2问题,我可以设置R和Jupyter笔记本,以便可以使用R创建一个新的笔记本,因此这似乎不是R / Jupyter的通讯问题。

I am running: 我在跑步:

OS X (El Capitan)
Python 2.7.12 :: Anaconda 4.1.1 (x86_64)
R version 3.3.1 (2016-06-21) (located as in /Users/myName/anaconda/bin)
rpy2 2.8.3 (located in /Users/myName/anaconda/lib/python2.7/site-packages/)

Is there any way to get rpy2 to work with Jupyter notebook these days? 这些天有什么方法可以使rpy2与Jupyter笔记本一起使用吗?

This is looking like a conda issue to me (lzma present at build time, but missing at run time). 在我看来,这似乎是一个conda问题(在构建时出现lzma,但在运行时丢失)。

Is there any way to get rpy2 to work with Jupyter notebook these days? 这些天有什么方法可以使rpy2与Jupyter笔记本一起使用吗?

Probably more than one way to achieve it, but the docker container mentioned on the front page ( http://rpy2.bitbucket.org/ ) is getting all pieces together in one step. 可能有多种方法可以实现它,但是首页( http://rpy2.bitbucket.org/ )上提到的Docker容器将所有步骤整合在一起。

I was able to get this to work by reinstalling anaconda, and installing rpy2 through conda: 我能够通过重新安装anaconda并通过rpy2安装rpy2来使其工作:

conda install rpy2

This will install R and lots of dependencies for anaconda. 这将为anaconda安装R和许多依赖项。 Use this R and not the system R . 使用此R而不是系统R The PATH should be automatically updated after anaconda is installed, but just in case, make sure to prepend anaconda: 安装anaconda之后, PATH应该会自动更新,但以防万一,请确保在anaconda之前添加:

setenv PATH /Users/myName/anaconda2/bin:$PATH

It critical that rpy2 be able to find the Renviron file, which should be newly installed within anaconda. 至关重要的rpy2能够找到Renviron文件,该文件应在anaconda中重新安装。 I found mine here (I just searched for it using spotlight): 我在这里找到了我(我只是使用聚光灯搜索了它):

/Users/myName/anaconda2/lib/R/

which I then made into the R_HOME variable that rpy2 requires to find Renviron . 然后将其放入rpy2所需的R_HOME变量中,以找到Renviron I also specified my username: 我还指定了用户名:

setenv R_HOME /Users/myName/anaconda2/lib/R/
setenv R_USER myName

(note that which R will return /Users/myName/anaconda2/bin/R/ , but this is NOT R_HOME . This tripped me up for ages). (请注意, which R将返回/Users/myName/anaconda2/bin/R/ ,但这不是R_HOME 。这使我绊倒了很R_HOME )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM