Michael Grünstäudl (Gruenstaeudl), PhD

Postdoctoral Researcher at the Freie Universität Berlin

Python version of rPython

R shell vs. RStudio

 

NOTE: This blog post originally appeared on 12-Nov-2014 on the blog I kept when I was a postdoctoral researcher at the Ohio State University. I am reposting it here because several people have asked me about this very topic lately.

 

On several occasions I have wondered which criterion the R package rPython employs to set the version of Python it interacts with. According to the installation file of rPython, “[b]y default, the package will be installed using the Python version given by $ python –version”. That seemed to be only part of the story, I thought, since my Linux system has Python 2.7.8 set as the default Python version, yet installations of the package via RStudio resulted in Python 3.4.1 being utilized by rPython:

> library(rPython)
> python.exec("import sys; info=sys.version")
> python.get("info")
[1] "3.4.2 (default, Oct 8 2014, 13:44:52) \n[GCC 4.9.1 20140903 (prerelease)]"

What eluded me, however, was to evaluate if the command “python –version” would return Python 2.7.8, when run from RStudio, from where I usually install my R packages! Guess what: It does not.RStudio and the R shell invoke the bash shell differently, as evidenced by the following example:

In RStudio:

> system("python – version")
Python 3.4.2

In R shell:

> system("python – version")
Python 2.7.8

Hence, if I wish to have rPython interact with Python 2.7.8, I must install the package from the R shell.

 

Der Beitrag wurde am Friday, den 6. November 2015 um 20:38 Uhr von Michael Grünstäudl veröffentlicht und wurde unter Allgemein abgelegt. Sie können die Kommentare zu diesem Eintrag durch den RSS 2.0 Feed verfolgen. Sie können einen Kommentar schreiben, oder einen Trackback auf Ihrer Seite einrichten.

Leave a Reply

Captcha
Refresh
Hilfe
Hinweis / Hint
Das Captcha kann Kleinbuchstaben, Ziffern und die Sonderzeichzeichen »?!#%&« enthalten.
The captcha could contain lower case, numeric characters and special characters as »!#%&«.