RPython using python installation incorrectly on Mac OSX

I installed python 2.7.8 along with 2.7.5, which comes with OSX 10.9.4.

Now, how can I point rPython to python 2.7.8?

Attempt # 1

I modified OSX .bash_profile as follows to point everything to a new 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 launches a 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 seems that .bash_profile not used by R at all ... so I tried changing PATH inside 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 uninstalling and reinstalling the rPython package, thinking that it was using the version of Python that was detected during installation. Bad luck.

Attempt # 4

I tried to install from the source to make sure that this is something ... no luck.

Update

So, it seems that the problem is not related to rPython itself.

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

The rPython package is dependent on Python (> = 2.7).

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

On systems where multiple versions of Python coexist, the user can select the version of Python to use during installation. By default, the package will be installed using the Python version specified

$ python --version

When I run this in the terminal ..

 mba:src tommy$ python --version Python 2.7.8 

But when I launched it in R ...

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

So the problem is that R does not use OSX .bash_profile . I 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 while working with 2.7.8 ?

+6
r rpython
source share
5 answers

I install the following commands in RStudio, hope this 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 
+5
source share

I know this is an old question, but I ran into the same problem as the OP, and this is the solution that I found workable.

First I added RPYTHON_PYTHON_VERSION=3 to my ~/.bash_profile . Instead of installing rPython using install.packages I downloaded the source from CRAN and installed it from the command line using R CMD INSTALL . This worked perfectly and discovered the python3 version that I installed on my system.

+2
source share

You can look at the INSTALL rPython file (sorry, maybe I should make it more explicit). It has a section on how to install rPython using the desired version of Python when several coexist. It says:

On systems where multiple versions of Python coexist, the user can select the version of Python to use during installation. By default, the package will be installed using the Python version specified

 $ python --version 

but you can choose another if the environment variable RPYTHON_PYTHON_VERSION is set accordingly.

For example, if it is defined as

  RPYTHON_PYTHON_VERSION=3.2 

he will try to use Python 3.2 (looking for python3.2 and python3.2-config in the path). If set to

  RPYTHON_PYTHON_VERSION=3 

it will be installed against the "canonical" version of Python on the system in branch 3.x.

+1
source share

I came across this post trying to get R to use the right version of Python and found a solution that worked for me (using Rstudio on OSX Yosemeti).

Here is my Python terminal that I want to find R:

 $ which python /usr/local/bin/python 

In R, system('which python') is /usr/bin/python . I see that this is because /usr/bin is to the right of /usr/local/bin in Sys.getenv('PATH') .

I tried changing my PATH to ~/.Renviron or ~/.Rprofile , but this did not fix the problem. This is because there was another Rprofile file before starting the kernel.

To find all the Rprofile files on my system, I Rprofile following commands:

 cd /usr sudo find . -name "*Rprofile*" -print 

One of the files, R_HOME/library/base/R/Rprofile , contains code that says it deals with PATH conflicts in my OS. I think he chose the wrong WAY of possible options. By adding the following line at the end of this file, I showed the correct path in Rstudio after restarting my R kernel:

 .Internal(Sys.setenv("PATH", paste("/usr/local/bin", Sys.getenv("PATH"), sep=":"))) 
+1
source share

what worked for me is that I specify lib and version in install.packages, like this

 install.packages("rPython",lib= "path_to_your_R/R/library/3.1", configure.vars= "RPYTHON_PYTHON_VERSION=3") 

And it is really installed with the python version which is under 3.x

+1
source share

All Articles