没有名为“ dtw”的软件包

时间:2020-09-27 02:44:51

标签: python r google-colaboratory rpy2

我正在使用Google colab,我试图通过rpy2使用r包,但它给我一个错误,如何在Google colab中将此包装添加到rpy2中。 这是我的代码。

import numpy as np
import rpy2.robjects.numpy2ri
rpy2.robjects.numpy2ri.activate()
from rpy2.robjects.packages import importr
import rpy2.robjects as robj

R = rpy2.robjects.r
DTW = importr('dtw')

错误:

 R[write to console]: Error in loadNamespace(name) : there is no package called ‘dtw’
Calls: <Anonymous> ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart

---------------------------------------------------------------------------
RRuntimeError                             Traceback (most recent call last)
<ipython-input-272-15b6cecae626> in <module>()
      6 
      7 R = rpy2.robjects.r
----> 8 DTW = importr('dtw')

2 frames
/usr/local/lib/python3.6/dist-packages/rpy2/rinterface.py in __call__(self, *args, **kwargs)
    787                     error_occured))
    788             if error_occured[0]:
--> 789                 raise embedded.RRuntimeError(_rinterface._geterrmessage())
    790         return res
    791 

RRuntimeError: Error in loadNamespace(name) : there is no package called ‘dtw’
Calls: <Anonymous> ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart

1 个答案:

答案 0 :(得分:0)

来自dtw's github page

要安装该软件包的最新稳定版本,请在R控制台中发出以下命令:

install.packages("dtw")