简体   繁体   English

Python-Rpy2-无法导入一堆软件包

[英]Python - Rpy2 - Can't import a bunch of packages

I've just started using rpy2 with Python. 我刚刚开始在Python中使用rpy2。 I've installed it and am able to do basic things, like call R's plot function from inside Python. 我已经安装了它并且能够做一些基本的事情,例如从Python内部调用R的plot函数。 For everything I've done, I've used import calls like: 对于我所做的一切,我都使用了导入调用,例如:

import rpy2
import rpy2.robjects

From robjects I can do most things I want to do. 在robjects中,我可以做我想做的大多数事情。 However, if I want to use things like ggplot2, I am unable to get the relevant imports to work. 但是,如果我想使用ggplot2之类的东西,则无法使相关的导入工作。 Following the steps here , I try: 按照这里的步骤,我尝试:

from rpy2.robjects.packages import importr

But I get an error message telling me that there is no module called "packages." 但是我收到一条错误消息,告诉我没有称为“程序包”的模块。 I'm not really sure why this is happening, as I am able to import other things from robjects, like rpy2.robjects.numpy2ri. 我不太确定为什么会这样,因为我能够从robjects导入其他内容,例如rpy2.robjects.numpy2ri。 I'm hoping this is some obvious problem other people have dealt with! 我希望这是其他人已经解决的一些明显问题! I did some googling and tried messing around with the env variable $PYTHONPATH but I don't think that is the issue. 我做了一些谷歌搜索,并尝试弄乱环境变量$ PYTHONPATH,但是我不认为这是问题。

packages is new in 2.1. packages是2.1中的新功能。 You're probably still using 2.0.x. 您可能仍在使用2.0.x。

You can use the normal library() command from robjects.r to load a library in rpy2 2.0.x: 您可以使用robjects.r中的普通library()命令在rpy2 2.0.x中加载库:

from rpy2.robjects import r
r.library("lattice")
r.library("ggplot2")

Or you can upgrade to the 2.1 alpha and see if the new way works for you. 或者,您可以升级到2.1 Alpha,然后查看新方法是否适合您。

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

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