6

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!

myClone
  • 1,609
  • 5
  • 17
  • 28

2 Answers2

2

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.

Richard Careaga
  • 628
  • 1
  • 5
  • 11
1

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
Spaceghost
  • 6,835
  • 3
  • 28
  • 42
  • Thanks! @ S.Lott, yeah, I used sudo easy_instal rpy2 and it appeared to do *something* but then when I open up IDLE and import rpy2 I get a traceback error. – myClone Sep 17 '10 at 05:08
  • Also, @Martin: rpy2 is there. Where do I go to enter the "which python" statement? In python? In R? Confused. Do I need to install something on the R side of things first for this to work? Thanks... – myClone Sep 17 '10 at 05:14
  • @Martin--answered my first question--locate via Terminal. The location is here: /Library/Frameworks/Python.framework/Versions/2.6/bin/python Now what? It looks like I have two folders labeled py26-rpy2: one stored in /opt/local/var/macports/build and another stored in /opt/local/var/macports/logs. – myClone Sep 17 '10 at 05:28
  • Don't forget there may be multiple versions of Python installed. Start a terminal and type 'which python' and it will show you the version that will be run when you type python without a path in front. If you use locate, it will not observe your PATH variable and will just find the first match on the system. – Spaceghost Oct 01 '10 at 21:34