gpt4 book ai didi

python - R运行时错误: Error in loadNamespace(name) : there is no package called 'forecast'

转载 作者:行者123 更新时间:2023-12-01 08:03:21 25 4
gpt4 key购买 nike

我尝试使用rpy2在Python中安装forecast包:

from rpy2.robjects.packages import importr
from rpy2.robjects import r
fore = importr("forecast")

但它给出了一些错误:

RRuntimeError Traceback (most recent call last)
<ipython-input-2-07185d7e0d3a> in <module>
1 from rpy2.robjects.packages import importr
2 from rpy2.robjects import r
----> 3 fore = importr("forecast")

~\Anaconda3\lib\site-packages\rpy2-2.9.4-py3.7-win-amd64.egg\rpy2\robjects\packages.py in importr(name, lib_loc, robject_translations, signature_translation, suppress_messages, on_conflict, symbol_r2python, symbol_check_after, data)
451 if _package_has_namespace(rname,
452 _system_file(package = rname)):
--> 453 env = _get_namespace(rname)
454 version = _get_namespace_version(rname)[0]
455 exported_names = set(_get_namespace_exports(rname))

RRuntimeError: Error in loadNamespace(name) : there is no package called 'forecast'

最佳答案

当我尝试加载另一个尚未安装的软件包时,我发现了相同的错误消息。例如,我尝试加载名为 forecast 的包。这是我的方法:

  1. 尝试打开您的 R 程序,并尝试通过键入 install.packages("forecast") 进行手动安装。然后,您可以重新加载(重新启动)python 脚本,尝试做同样的事情(加载包 forecast)

  2. 您可以从 Python 中手动安装您愿意使用/加载的任何未解析的软件包。这是我的代码:rpy2.robjects.r('install.packages("forecast")')

或者你可以像这样自动化

import rpy2.robjects as ro

package_name = "forecast"

try:
pkg = importr(package_name)
except:
ro.r(f'install.packages("{package_name}")')
pkg = importr(package_name)
pkg

希望对你有帮助

关于python - R运行时错误: Error in loadNamespace(name) : there is no package called 'forecast' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55638109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com