【问题标题】:Unable to import rmgarch model in Colab Python environment无法在 Colab Python 环境中导入 rmgarch 模型
【发布时间】:2020-10-20 07:11:18
【问题描述】:

我想使用 rmgarch 进行多变量时间序列分析,因为 Python 没有多变量模型,我正在尝试使用 R 的 rmgarch 包。

我正在尝试使用以下代码在 Colab Python 环境中导入 rmgarch 模型。

下面是它返回的错误,有人遇到过这样的问题吗?

from rpy2.robjects.packages import importr
package_name = "rmgarch"

try:
    pkg = importr(package_name)
except:
    ro.r(f'install.packages("{package_name}")')
    pkg = importr(package_name,lib_loc='/usr/local/lib/R/site-library')
pkg

错误:

R[write to console]: Error in loadNamespace(name) : there is no package called ‘rmgarch’
Calls: <Anonymous> ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
R[write to console]: Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
R[write to console]: also installing the dependencies ‘gmp’, ‘Rmpfr’, ‘Bessel’
R[write to console]: The downloaded source packages are in
    ‘/tmp/RtmpI6uWBQ/downloaded_packages’
R[write to console]: Error in loadNamespace(name) : there is no package called ‘rmgarch’
Calls: <Anonymous> ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
R[write to console]: In addition: 
R[write to console]: Warning messages:
R[write to console]: In install.packages("rmgarch") :
R[write to console]:  installation of package ‘gmp’ had non-zero exit status
R[write to console]: 2: 
R[write to console]: In install.packages("rmgarch") :
R[write to console]:  installation of package ‘Rmpfr’ had non-zero exit status
R[write to console]: In install.packages("rmgarch") :
R[write to console]:  installation of package ‘Bessel’ had non-zero exit status
R[write to console]: In install.packages("rmgarch") :
R[write to console]:  installation of package ‘rmgarch’ had non-zero exit status
---------------------------------------------------------------------------
RRuntimeError                             Traceback (most recent call last)
<ipython-input-49-e4fba63eb683> in <module>()
      7 try:
----> 8     pkg = importr(package_name)
      9 except:
6 frames
RRuntimeError: Error in loadNamespace(name) : there is no package called ‘rmgarch’
Calls: <Anonymous> ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
During handling of the above exception, another exception occurred:
RRuntimeError                             Traceback (most recent call last)
/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 ‘rmgarch’
Calls: <Anonymous> ... loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart

【问题讨论】:

    标签: python r machine-learning time-series google-colaboratory


    【解决方案1】:

    我有一个非常相似的问题,对我来说,原因是 Colab 无法安装 gmp R 包,这是几个 R 包所必需的。

    解决方法是您必须手动安装 gmp 库:

    1. 如果你在 R 内核中,那么system("sudo apt-get install libgmp-dev")
    2. 如果你在 Python 内核中(就像你一样),那么我认为 !apt-get -qq install -y libgmp-dev

    之后,使用 gmp 的包的 R 包导入应该没问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-02
      • 2018-10-26
      • 1970-01-01
      • 1970-01-01
      • 2020-10-18
      • 1970-01-01
      相关资源
      最近更新 更多