我正在尝试为 IPython 笔记本使用 rmagic 扩展,通过 Enthought Canopy 使用 Python 2.7.6。
当我尝试以下示例时:
import numpy as np
import pylab
X = np.array([0,1,2,3,4])
Y = np.array([3,5,4,6,7])
pylab.scatter(X, Y)
%Rpush X Y
%R lm(Y~X)$coef
我收到一个错误:
AttributeError Traceback (most recent call last)
<ipython-input-7-96dff2c70ba0> in <module>()
1 get_ipython().magic(u'Rpush X Y')
----> 2 get_ipython().magic(u'R lm(Y~X)$coef')
…
/Users/hrob/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/extensions/rmagic.pyc in eval(self, line)
212 res = ro.r("withVisible({%s})" % line)
213 value = res[0] #value (R object)
--> 214 visible = ro.conversion.ri2py(res[1])[0] #visible (boolean)
215 except (ri.RRuntimeError, ValueError) as exception:
216 warning_or_other_msg = self.flush() # otherwise next return seems to have copy of error
AttributeError: 'module' object has no attribute 'ri2py'
我找不到其他人遇到同样的问题并且不知道自己解决问题。但是,conversion.py 中没有 ri2py 的定义。
我最初安装了 Anaconda 并通过它运行 python notebook,结果完全相同。
rpy2(版本 2.4.0)安装成功,但是当我测试它时,我得到 1 个预期的失败,如下所示:
python -m 'rpy2.robjects.tests.__init__'
…
testNewWithTranslation (testFunction.SignatureTranslatedFunctionTestCase) ... expected failure
不知道有没有关系
任何人都可以建议问题可能是什么以及我如何解决它?我使用的 python、R 等版本是否兼容,或者我是否需要重新安装/更新某些内容?
最佳答案
您在使用 %load_ext rmagic
?
如果是这样,请尝试使用 %load_ext rpy2.ipython
反而。
这是其中之一 new features在 2.4.0 版本中。
关于r - IPython 笔记本和 rmagic/rpy2 : cannot find module ri2py (OSX 10. 8.5、python 2.7、R 3.1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23912243/