9

My question is:
How can I change the python version to anaconda 3.5 and can use modules that have installed in anaconda in RStudio.

I'm using RStudio Version 0.99.891
R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.3 (El Capitan)

and I have installed Anaconda3, set python 3.5 as default python version.
$ python
Python 3.5.1 |Anaconda custom (x86_64)| (default, Dec 7 2015, 11:24:55)

However, in RStudio,

system("python --version")
Python 2.7.10

I tried to change it by following method:

Sys.setenv(PATH = paste("/Users/UserName/anaconda3/bin", Sys.getenv("PATH"), sep=":"))
system("python --version")
Python 3.5.1 :: Anaconda custom (x86_64)

It seems good, but actually it is not.

python.exec("import os")
python.exec("import inspect")
python.exec("inspect.getfile(os)")
python.exec("print(inspect.getfile(os))")
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.pyc

python.exec("import pandas as pd")
Error in python.exec("import pandas") : No module named pandas

Thanks.

Qinqing Liu
  • 412
  • 1
  • 6
  • 10
  • I have had this problem and been unable to resolve it. It may be worth mentioning on the rstudio site. – lmo Apr 20 '16 at 00:04
  • This question has been asked a while ago but if you still have this issue, here is a SO link that may answer your question (one of the answers uses the `Sys.setenv` function to point to a different version to python: http://stackoverflow.com/questions/25383030/rpython-using-wrong-python-installation-on-mac-osx – steveb Oct 23 '16 at 06:22

2 Answers2

8

Put the following line in your .Rprofile:

Sys.setenv(PATH = paste("/home/your_user_name/anaconda3/bin", Sys.getenv("PATH"), sep=":")) 

Proof:

> system("python --version")
Python 3.6.1 :: Anaconda custom (64-bit)
Sergey Bushmanov
  • 23,310
  • 7
  • 53
  • 72
3

Just to complete @Sergey answer and for anyone who needs it, you can edit .Rprofile directly from R with the following command:

library(devtools)
usethis::edit_r_profile()
pedro magalhaes
  • 176
  • 2
  • 6