简体   繁体   中英

Integrating Python with R

  1. I am trying to install the appropriate packages to allow easy access to R from Python.

  2. From what I understand, I have to use a command called easy_install to install a program called py2

  3. But to do that, I have to install easy_install by running a .egg file downloaded as if it were a shell script.

How do I run my downloaded file as if it were a shell scirpt? And once I have done that, if I just run easy_install py2, will the R interface be installed.

Appropriate links are here:

  1. http://rpy.sourceforge.net/rpy2_download.html

  2. http://peak.telecommunity.com/DevCenter/EasyInstall

  3. http://pypi.python.org/pypi/setuptools

I suggest installing pip, an alternative to easy_install, first.

I am not sure what tools OSX comes with for downloading the bootstrap code for pip (curl, wget), but I assume you have python 2.X installed, which you can check with

python --version

Run the following python program, by saving this as download.py and then run 'python download.py':

import os
import urllib2
from subprocess import call

def download_file_and_run(url):
    basename = os.path.basename(url)
    fp = urllib2.urlopen(url)
    open(basename, 'wb').write(fp.read())
    fp.close()
    call(['python', basename])

download_file_and_run('http://python-distribute.org/distribute_setup.py')
download_file_and_run('https://raw.github.com/pypa/pip/master/contrib/get-pip.py')

now

pip --version 

should give you a version number like 1.1

Now install rpy2 using:

pip install rpy2

This assumes R is installed, if not the installer will complain with an error: Tried to guess R's HOME but no R command in the PATH.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM