RStudio Python Version Change on Mac

北战南征 提交于 2020-01-02 03:38:26

问题


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.


回答1:


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)



回答2:


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()


来源:https://stackoverflow.com/questions/36705878/rstudio-python-version-change-on-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!