gpt4 book ai didi

python - Rpy2 找不到包

转载 作者:太空狗 更新时间:2023-10-29 21:46:12 26 4
gpt4 key购买 nike

我在 windows 7 64 上使用 Rpy2,加载包时遇到问题:

在 R 中:

using(mi)

在 python 中:

from rpy2.robjects.packages import importr
mi=importr('mi')

---------------------------------------------------------------------------
RRuntimeError Traceback (most recent call last)
<ipython-input-30-2d393a6df544> in <module>()
----> 1 mi=importr('mi')

C:\Anaconda\lib\site-packages\rpy2\robjects\packages.pyc in importr(name, lib_loc, robject_translations, signature_translation, suppress_messages, on_conflict, data)
397 if _package_has_namespace(rname,
398 _system_file(package = rname)):
--> 399 env = _get_namespace(rname)
400 version = _get_namespace_version(rname)[0]
401 exported_names = set(_get_namespace_exports(rname))

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

有什么建议吗?

最佳答案

我遇到了类似的问题:

rpy2.rinterface.RRuntimeError: Error in loadNamespace(name) : there is no package called speedglm

我注意到问题是 rpy2 不知道所有 R 库的位置。在我的例子中,输入(在 R 中)

.libPaths()

给我

[1] "/home/nbarjest/R/x86_64-redhat-linux-gnu-library/3.4"
[2] "/usr/lib64/R/library"
[3] "/usr/share/R/library"

同时,输入(在 Python 3 中)

import rpy2.rinterface
rpy2.rinterface.set_initoptions((b'rpy2', b'--no-save', b'--no-restore', b'--quiet'))
from rpy2.robjects.packages import importr
base = importr('base')
print(base._libPaths())

只给了我

[1] "/home/nbarjest/R/x86_64-redhat-linux-gnu-library/3.4"

我找不到将其他两个路径附加到 base._libpath() 的方法。如果你找到办法做到这一点,请告诉我。我使用了另一种解决方法:

import rpy2
import rpy2.robjects as RObjects
from rpy2.robjects.packages import importr
utils = importr("utils")
d = {'print.me': 'print_dot_me', 'print_me': 'print_uscore_me'}
try:
thatpackage = importr('speedglm', robject_translations = d, lib_loc = "/home/nbarjest/R/x86_64-redhat-linux-gnu-library/3.4")
except:
try:
thatpackage = importr('speedglm', robject_translations = d, lib_loc = "/usr/lib64/R/library")
except:
thatpackage = importr('speedglm', robject_translations = d, lib_loc = "/usr/share/R/library")

这行得通。我希望遇到同样问题的其他人觉得这很有用。

关于python - Rpy2 找不到包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28367799/

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