10

I am trying to install rpy2 and I am facing a common issue. Unfortunately all the solution I have found are for win7

I have installed a Python 2.7 and R 2.15. then I write on the terminal

easy_install rpy2

or, alternatively

pip install rpy2

Same result:

Tried to guess R's HOME but no R command in the PATH

What I should do?

user2988577
  • 3,997
  • 7
  • 21
  • 21
  • How do you usually invoke `r` from the commmandline? – mgilson Nov 25 '13 at 20:36
  • Never did it: I've installed it to use with rpy2. However I can launch it from the application folder clicking on the icon; I can get informations too: it says R.app but if I try it on the terminal it does not seems to work. – user2988577 Nov 25 '13 at 20:41
  • open your terminal type `echo export path=$path./bin/R/ >> ~/.bashrc` and restart your computer (replace `/bin/R` with the path to your actual R executable ... I think that will work at least (I think macs have .bashrc files) – Joran Beasley Nov 25 '13 at 20:43
  • What I should expect to see after that command? It does not do anything. Nor an error message. – user2988577 Nov 25 '13 at 20:55
  • 2
    @JoranBeasley -- A restart seems a little heavy handed here, don't you think? Wouldn't you expect a simple `source ~/.bashrc` to work? – mgilson Nov 25 '13 at 21:04
  • @user2988577 -- After you've run that command (presumably successfully), and if you source the file as I suggest above, then you can retry your `rpy2` install... See if it works. – mgilson Nov 25 '13 at 21:05
  • Nope. Writing source ~/.bashrc on terminal does noting (noticiable), not error, not output... And the error in the easy_install is still there. – user2988577 Nov 25 '13 at 21:14
  • type `tail ~/.bashrc` and make sure that command is there on the last line @mgilson yes you are right :P source should be fine ... I only run *nix from virtual boxes so I dont mess with that much – Joran Beasley Nov 25 '13 at 21:38
  • This returns export path=./bin/R/ export path=./bin/R/./bin/R/ The error is still there. – user2988577 Nov 25 '13 at 21:49
  • 1
    Was this ever settled? – wolfsatthedoor Aug 31 '14 at 03:13
  • I wasn't able to set the issue, so I went on another avenue. But it seems I'm not the only one. – user2988577 Feb 01 '16 at 20:42
  • Reported to the rpy2 project as https://bitbucket.org/rpy2/rpy2/issues/338/ (it seems no one did this back in 2013) – Peter Cock Mar 24 '16 at 14:12
  • Possible duplicate of [Encountering error when installing rpy2: Tried to guess R's HOME but no R command in the PATH](https://stackoverflow.com/questions/30083067/encountering-error-when-installing-rpy2-tried-to-guess-rs-home-but-no-r-comman) – LondonRob Jul 17 '17 at 10:35

5 Answers5

4

Make sure you have R installed

brew install r

Then install rpy

pip install rpy2
louis_guitton
  • 5,105
  • 1
  • 31
  • 33
2

The rpy2 code is doing the wrong check. R might be perfectly fine, but rpy2 is using an unreliable check.

To check for R, the rpy2 uses subprocess.check_output. However, that was introduced (AFAIK) in python 2.7.

If you're using a version of python less than 2.7 then you should update to at least 2.7.

If you must use python 2.6, then you should look at this answer to see how to force subprocess.check_output into python 2.6, finally allowed you to install rpy2. This is what I had to do as I was unable to update the version of python.

Download the rpy2 code, and edit its setup.py and insert the code from that answer.

Community
  • 1
  • 1
Aaron McDaid
  • 26,501
  • 9
  • 66
  • 88
  • @dww, updating python would also resolve this. That's the easiest solution of course! But I forgot about that because I don't have control of the server that I use and can't update the system-wide python. I'll edit my answer – Aaron McDaid Aug 16 '16 at 09:55
1
  1. use easy_install rpy2 and it works just fine.

http://rpy.sourceforge.net/rpy2/doc-2.2/html/overview.html#download

Make sure you have setuptools installed.

If you do not know how to do that, check this link

You can just run ez_setup.py and let it decide for you.

  1. Add C:\Program Files\R\R-2.12.1\bin\i386 (the path to R.dll) to the environment variable PATH

  2. Add an environment variable R_HOME with C:\Program Files\R\R-2.12.1

  3. Add an environment variable R_USER with your Windows username

CheTesta
  • 577
  • 4
  • 17
moiaussi06
  • 221
  • 3
  • 11
1

I had the same problem (on a Mac) and none of the solutions I found online worked. The only thing that worked for me was:

conda update python

pip install rpy2

0

Installation worked for me when I did

pip install rpy2

but not when I did

sudo pip install rpy2

So in case you were using sudo and not mentioning it, this might help you. I also tried manually installing from source, which worked when I used just 'python setup.py install' for the install step, but not with sudo!

I did this on CentOS 7 with Python 2.7 and R 3.2 (as the root user). On sudo's behavior, see this question.

Community
  • 1
  • 1
DavidArndt
  • 406
  • 2
  • 6