Change version of python in rPython?

597 Views Asked by At

I'm trying to run tensor flow with rPython in RStudio and rPython uses a different version of python than the one in my terminal.

How do you change which version rPython uses?

1

There are 1 best solutions below

0
On

One way is to reinstall the rPython-package and specify which python version to use:

# Lets assume it is already connected to python 3.5.3
library(rPython)                                                                                                                                                                                                                                                     
python.exec("import sys")                                                                                                                                                                                                                                            
python.exec("print (sys.version)")                                                                                                                                                                                                                                   
# 3.5.3 (default, Jan 19 2017, 14:11:04)                                                                                                                                                                                                                                 
# [GCC 6.3.0 20170118]

# Now lets connect it instead to python 2.7.13                                                                                                                                                                                                                                                   
detach("package:rPython", unload=TRUE)                                                                                                                                                                                                                               
install.packages("rPython",lib= "/home/userid/R/x86_64-pc-linux-gnu-library/3.4", configure.vars= "RPYTHON_PYTHON_VERSION=2")
# omitted install reporting of rPython for space #
library(rPython)                                                                                                                                                                                                                                                     
python.exec("import sys")                                                                                                                                                                                                                                            
python.exec("print (sys.version)")                                                                                                                                                                                                                                   
# 2.7.13 (default, Jan 19 2017, 14:48:08)                                                                                                                                                                                                                                
# [GCC 6.3.0 20170118]