安装reticulate包--连接R与Python的接口
普通的安装方法reticulate包版本太旧,容易报错,使用GitHub安装
library(devtools)
install_github("rstudio/reticulate")
删掉了多出来的 .Renviron 和 .Rprofile
当下载好的Anaconda后,在Rstudio中应设置好Python的路径
不然会报错:
> py_available()
[1] FALSE
> repl_python()
Error: Error 1 occurred creating conda environment C:/Users/vic/AppData/Local/r-miniconda/envs/r-reticulate
或
reticulate:repl_python()
Collecting package metadata (current_repodata.json): ...working... failed
···
# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<
Error: object 'reticulate' not found
参考可见(https://www.jianshu.com/p/94e2700bd2f1)
正确的脚本
> py_available()
[1] FALSE
检查路径
> Sys.setenv(RETICULATE_PYTHON="C:\\Users\\vic\\anaconda3\\python.exe")
> use_python("C:/Users/vic/anaconda3/python.exe")
> py_available()
[1] FALSE
> use_python("C:\\Users\\vic\\anaconda3\\python.exe")
> py_config()
python: C:/Users/vic/anaconda3/python.exe
libpython: C:/Users/vic/anaconda3/python38.dll
pythonhome: C:/Users/vic/anaconda3
version: 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)]
Architecture: 64bit
numpy: C:/Users/vic/anaconda3/Lib/site-packages/numpy
numpy_version: 1.19.2
NOTE: Python version was forced by RETICULATE_PYTHON
> py_available()
[1] TRUE
> #查看conda版本
> conda_version()
[1] "conda 4.10.1"
> #启动
> repl_python()
Python 3.8.5 (C:/Users/vic/anaconda3/python.exe)
Reticulate 1.18 REPL -- A Python interpreter in R.
网友评论