Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rPython using wrong python installation on Mac OSX

Tags:

r

rpython

I've installed python 2.7.8 alongside the 2.7.5 which comes with OSX 10.9.4.

Now how can I point rPython to python 2.7.8?

Attempt #1

I've modified the OSX .bash_profile as follows to point everything to the newer python installation.

export PATH=/usr/local/Cellar/python/2.7.8/bin/:$PATH:usr/local/bin:

And now when I run python from the terminal, it correctly runs the newer version

mba:~ tommy$ which python
/usr/local/Cellar/python/2.7.8/bin//python

However, rPython, still sees 2.7.5.

> library(rPython)
Loading required package: RJSONIO
> python.exec("import sys; print(sys.version)")
2.7.5 (default, Mar  9 2014, 22:15:05) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]

Attempt #2

It looks like the .bash_profile doesn't get used by R at all... so I've tried to modify the PATH within R. But still no luck.

> Sys.getenv("PATH")
[1] "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"
> Sys.setenv(PATH = "usr/local/Cellar/python/2.7.8/bin")
> library(rPython)
Loading required package: RJSONIO
> python.exec("import sys; print(sys.version)")
2.7.5 (default, Mar  9 2014, 22:15:05) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]

Attempt #3

I tried removing and re-installing the rPython package thinking perhaps it was using the version of Python that it found upon installation. No luck either.

Attempt #4

I've tried installing from source to see if that does anything... no luck.

Update

Okay so it looks like the problem isn't anything to do with rPython itself.

http://cran.r-project.org/web/packages/rPython/INSTALL

Package rPython depends on Python (>= 2.7).

It requires both Python and its headers and libraries. These can be found in python and python-dev packages in Debian-like Linux distributions.

In systems where several Python versions coexist, the user can choose the Python version to use at installation time. By default, the package will be installed using the Python version given by

$ python --version

When I run that in the terminal..

mba:src tommy$ python --version
Python 2.7.8

But when I run it in R...

> system("python --version")
Python 2.7.5

So the problem is simply that R doesn't use OSX's .bash_profile. I'll need to figure out how to change PATH outside of .bash_profile, or get R to use .bash_profile.

What else can I try to get rPython working with 2.7.8?

like image 965
Tommy O'Dell Avatar asked Aug 19 '14 12:08

Tommy O'Dell


Video Answer


1 Answers

I setup the following commands in RStudio, hope these help.

> system("python --version")
Python 2.7.10

> Sys.setenv(PATH = paste("/usr/local/bin", Sys.getenv("PATH"),sep=":"))

> system("python --version")
Python 2.7.11
like image 85
madeinQuant Avatar answered Nov 03 '22 20:11

madeinQuant