Rpy2 找不到包 [英] Rpy2 not finding package

查看:51
本文介绍了Rpy2 找不到包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 7 64 上使用 Rpy2 并且在加载包时遇到问题:

I'm using Rpy2 on windows 7 64 and having trouble loading a package:

using(mi)

在蟒蛇中:

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 中)

I noticed that the issue is that rpy2 does not know the location of all R libraries. In my case, typing (in 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 中)

While, typing (in 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() 的方法.如果你找到了一种方法,请告诉我.我使用了另一种解决方法:

I couldn't find a way to append the other two paths to base._libpath(). If you find a way to do it, please let me know. I used another workaround:

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")

这有效.我希望其他有同样问题的人觉得这很有用.

This works. I hope other people who have the same problem find this useful.

这篇关于Rpy2 找不到包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆