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
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!
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.
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.
rpy2 is an interface to R running embedded in a Python process.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With