开发者

Python - Rpy2 - Can't import a bunch of packages

I've just started using rpy2 with Python. I've installed it and am able to do basic things, like call R's plot function from inside Python. 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. However, if I want to use things like ggplot2, I am unable to get the relevant imports to work. 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 "pa开发者_开发问答ckages." I'm not really sure why this is happening, as I am able to import other things from robjects, like 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.


packages is new in 2.1. You're probably still using 2.0.x.


You can use the normal library() command from robjects.r to load a library in 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜