Mac上的RStudio Python版本更改 [英] RStudio Python Version Change on Mac

查看:333
本文介绍了Mac上的RStudio Python版本更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是:
如何将python版本更改为anaconda 3.5,并可以使用RStudio中anaconda中已安装的模块.

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.

我正在使用RStudio版本0.99.891
R版本3.2.3(2015-12-10)
平台:x86_64-apple-darwin13.4.0(64位)
运行于:OS X 10.11.3(El Capitan)

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)

并且我已经安装了Anaconda3,将python 3.5设置为默认python版本.
$ python
Python 3.5.1 | Anaconda自定义(x86_64)| (默认值,2015年12月7日,11:24:55)

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)

但是,在RStudio中,

However, in RStudio,

system("python --version")
Python 2.7.10

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自定义(x86_64)

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(导入检查")
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 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(将熊猫作为pd导入")
python.exec("import pandas")中的错误:没有名为pandas的模块

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

谢谢.

推荐答案

在您的.Rprofile中放置以下行:

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

证明:

> system("python --version")
Python 3.6.1 :: Anaconda custom (64-bit)

这篇关于Mac上的RStudio Python版本更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆