Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Install rpy2 on Mac OS X

I am trying, so far unsuccessfully, at installing the rpy2 for python on my Mac OSX. I have tried Macports and DarwinPorts but have had no luck with

import rpy2

within the python shell environment. I don't know much about programming in Mac and I am a wiz at installing modules on a Windoze based system, but for the life of me cannot do a simple port on my Mac at home.


What I am after, if someone would be so kind, are "dumbed down" instructions for a successful install of rpy2 for Mac OSX Snow Leopard. Hopefully someone here has done this successfully and can outline the process they took? At least that is what I am hoping.

Many thanks in advance!

like image 882
myClone Avatar asked Sep 10 '10 20:09

myClone


People also ask

Do I need to install R to use rpy2?

rpy2 will typically require an R version that is not much older than itself. This means that even if your system has R pre-installed, there is a chance that the version is too old to be compaible with rpy2. At the time of this writing, the latest rpy2 version is 2.8 and requires R 3.2 or higher.

What version of R does rpy2 use?

Installing rpy2 You must have Python >=3.7 and R >= 4.0 installed to use rpy2 3.5. 2. Once R is installed, install the rpy2 package by running pip install rpy2 . If you'd like to see where you installed rpy2 on your machine, you can run python -m rpy2.

What is rpy2 package?

rpy2 is an interface to R running embedded in a Python process.


2 Answers

easy_install and rpy2 work fine together (just did it) but you need to have easy_install in sync with your specific python version. This comes down to controlling your $PATH and $PYTHONPATH environment variables so that the first Python directory that appears is the version you want and also has the easy_install version you want. Do not try to solve this by taking out the factory installed version of Python.

You set your path variables in your home directory. If you are using the default bash shell, check .bash_profile for

$ echo $PYTHONPATH /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/

which will tell you where and in what order installed packages are searched for

and

$ echo $PATH

/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:

Rather than giving a recipe for how to set these if needed, I encourage you to consult the usual sources because a little knowledge is dangerous and rendering the shell inoperative by reasonable, but wrong, guesses is a real danger.

like image 183
Richard Careaga Avatar answered Oct 15 '22 07:10

Richard Careaga


First check that you installed rpy2 successfully. Look in /opt/local/var/macports/software for anything with rpy2 in the title. It maybe called py26-rpy depending on the version of Python you are running.

If you see that then you just need to use the right path to Python .. check the default location of Python like this:

which python

This will return the location of the first Python found and will probably say /usr/bin/python but you should use the version that rpy2 was compiled against.. which lives in /opt/local/bin.

Try:

/opt/local/bin/python2.6

then:

import rpy2
like image 45
Spaceghost Avatar answered Oct 15 '22 08:10

Spaceghost