简体   繁体   English

Rpy2 找不到包

[英]Rpy2 not finding package

I'm using Rpy2 on windows 7 64 and having trouble loading a package:我在 Windows 7 64 上使用 Rpy2 并且在加载包时遇到问题:

in R:在 R:

using(mi)

in 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

Any suggestions?有什么建议?

I had a similar problem:我有一个类似的问题:

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

I noticed that the issue is that rpy2 does not know the location of all R libraries.我注意到问题是 rpy2 不知道所有 R 库的位置。 In my case, typing (in R)就我而言,输入(在 R 中)

.libPaths()

gave me给我

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

While, typing (in Python 3)同时,输入(在 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())

gave me only只给了我

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

I couldn't find a way to append the other two paths to base._libpath().我找不到将其他两条路径附加到 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.我希望其他有同样问题的人觉得这很有用。

For me, in importr , the argument lib_loc inside it worked, putting the first path that appears in the output of .libPaths() in R, like:对我来说,在importr 中,它内部的参数lib_loc起作用,将出现在.libPaths()输出中的第一个路径放在 R 中,例如:

importr('name package', lib_loc="/home/nbarjest/R/x86_64-redhat-linux-gnu-library/3.4") , importr('name package', lib_loc="/home/nbarjest/R/x86_64-redhat-linux-gnu-library/3.4") ,

where the path is the path in the output example of the @Nbarjest answer.其中路径是@Nbarjest 答案的输出示例中的路径。

In python: Check the version of R being used by rpy2在 python 中:检查 rpy2 使用的 R 版本

import rpy2.robjects as robjects
robjects.r['version']

Check your rpy2 library location检查您的 rpy2 库位置

base = importr('base')
print(base._libPaths())

In R: Check your R library location for this version of r在 R 中:检查您的 R 库位置以获取此版本的 r

.libPaths()

copy the library installed in your version of r to the folder used by rpy2.将安装在您的 r 版本中的库复制到 rpy2 使用的文件夹中。

I also have this problem,and i copy the package i need to base._libPaths() ,here , and it works.我也有这个问题,我将需要的包复制到 base._libPaths() ,这里,它可以工作。

import rpy2.robjects as objects
from rpy2.robjects.packages import importer
base = importr('base')
base._libPaths()[0]

I had a similar problem.我有一个类似的问题。 I had to uninstall R and reinstall it with admin rights, then reinstall the R package while running R with admin rights, so it would install to the standard library location (not a personal library).我必须卸载 R 并以管理员权限重新安装它,然后在以管理员权限运行 R 的同时重新安装 R 包,这样它就会安装到标准库位置(不是个人库)。 Then add R to the PATH variable, and reinstall rpy2.然后将 R 添加到 PATH 变量中,并重新安装 rpy2。

这是在 rpy2 的问题跟踪器上交叉发布和回答的: https ://bitbucket.org/rpy2/rpy2/issue/265/windows-error-in-loadnamespace

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM