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?
what worked for me is that i specify the 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 indeed installed with python version which under 3.x
I know this is an old question, but I ran into the same problem as OP and this is the solution I found worked.
First, I added the RPYTHON_PYTHON_VERSION=3
to my ~/.bash_profile
. Instead of installing rPython
using install.packages
, I downloaded the source from CRAN and installed from the command line using R CMD INSTALL
. This worked fine and detected the python3
version I had installed on my system.
You can have a look at the rPython INSTALL file (sorry, perhaps I should make it more explicit). It has a section on how to install rPython using the desired Python version when several coexists. It says:
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
but it is possible to select a different one if the RPYTHON_PYTHON_VERSION environment variable is appropriately set.
For instance, if it is defined as
RPYTHON_PYTHON_VERSION=3.2
it 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 install against the "canonical" Python version in the system within the 3.x branch.
I came across this post trying to get R to use a desired Python version and found a solution which worked for me (using Rstudio on OSX Yosemeti).
Here is the Python my terminal uses, which is the one I want R to find:
$ which python
/usr/local/bin/python
In R, system('which python')
produces /usr/bin/python
. I can see that this is because /usr/bin
is to the right of /usr/local/bin
in Sys.getenv('PATH')
.
I tried changing my PATH in ~/.Renviron
or ~/.Rprofile
but it wasn't fixing the problem. This is because there was another Rprofile
file running right before kernel startup completed.
To find all the Rprofile
files on my system, I ran these commands:
cd /usr
sudo find . -name "*Rprofile*" -print
One of the files -- R_HOME/library/base/R/Rprofile
-- contained some code which said it dealt with PATH conflicts on my OS. I guess it chose the wrong PATH of the possible choices. Adding the following line to the end of that file, showed me the correct path in Rstudio after restarting my R kernel:
.Internal(Sys.setenv("PATH", paste("/usr/local/bin", Sys.getenv("PATH"), sep=":")))
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