Question

I am a bit of a noob on Mac and my python installation is refusing to acknowledge the existence of the rpy2 module on my mac. It looks like it only sees it as a Python 2.6 module. How do I make it visible in 2.7 ? Do I need to downgrade my python ? If so, how ? On the RPy2 web page (http://rpy.sourceforge.net/rpy2_download.html) Python 2.6 is recommended. Thanks!

mayumi@MAYUMI-iMac~:/ python --version
Python 2.7.6
mayumi@MAYUMI-iMac~:/ pip install rpy2
Requirement already satisfied (use --upgrade to upgrade): rpy2 in /Library/Python/2.6/site-packages/rpy2-2.3.8-py2.6-macosx-10.6-universal.egg
Cleaning up...
mayumi@MAYUMI-iMac~:/ python
Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import rpy2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named rpy2
>>> 
Was it helpful?

Solution

I also found it is difficult to successfully install rpy2 in OSX machines. Sometime it works, sometimes it doesn't, which is very annoying. I eventually settled with Anaconda Python distribution from https://store.continuum.io/cshop/anaconda/ to save all the troubles. Installing rpy2 never fails since the switch.

The default installation of Anaconda does not included rpy2, so you want to run the installation command, from Anaconda folder, bin subfolder

conda install rpy2

Depends on the version, you may get a bunch of warnings. Just ignore them.

Then rpy2 just works! Of course, only under the Anaconda python, not the other python version you may have installed on your machine.

enter image description here

You can run a few test to make sure rpy2 works, following this example: http://nbviewer.ipython.org/urls/raw.github.com/ipython/ipython/3607712653c66d63e0d7f13f073bde8c0f209ba8/docs/examples/notebooks/rmagic_extension.ipynb

bash commands, run in the folder /Users/YOUR_USER_NAME/anaconda/bin/:

user-Mac-Pro:bin user$ conda install rpy2

and it says:

Conda package not available for rpy2, attempting to install via pip
Downloading/unpacking rpy2
 Downloading rpy2-2.3.8.tar.gz (185kB): 185kB downloaded
 Running setup.py egg_info for package rpy2

If you don't have R installed it will complain with a few warnings and fetch R for you. Then there may be some other depreciation warnings dependents on what you have installed.

(I am not associated with Continuum in any way)

OTHER TIPS

You can see that pip installed to the site-packages to python 2.6 since you installed pip with python 2.6 it will default to use that library.

 rpy2 in /Library/Python/**2.6**/site-packages/rpy2-2.3.8-py2.6-macosx-10.6-universal.egg

You can redirect pip installation location or use easy_install2.7 which should be around in /usr/local/bin/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top