tony8310的个人博客分享 http://blog.sciencenet.cn/u/tony8310

博文

RStudio或R中miniconda tensorflow 环境的设置

已有 5979 次阅读 2021-11-3 00:22 |系统分类:科研笔记

最近尝试用R进行些简单的机器学习,在笔记本上配置好了环境,能正常运行代码;而在台式机上不能正常运行。经过自己尝试,结合资料,把一点经验记录如下:

不想安装Anaconda这条大蟒蛇,在Python环境设置时用miniconda。

>>>>1 必须安装miniconda
library(reticulate)
install_miniconda()

>>>>2 安装 tensorflow,在RStudio中选择相应环境的python
>>(1) 安装虚拟环境
  Try to follow the guide at   https://tensorflow.rstudio.com/installation/:
In your R-studio console :
    install.packages(tensorflow)
    library(tensorflow)
    install_tensorflow()
If you have not installed Anaconda / Miniconda manually, then at step no. 3, a prompt will ask your permission to install Miniconda. If you already have conda installed, then :
    Create new environment r-reticulate in conda : conda create -n r-reticulate
    Install tensorflow from R-studio console with parameters : install_tensorflow(method = 'conda', envname = 'r-reticulate')
---if not worked---
after Create new environment r-reticulate in conda
conda activate env r-reticulate
pip install tensorflow
下载之前建议设置pip清华源(用以提速)
设置下载源    pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
可以安装特定版本 pip install tensorflow==2.6.0
----then---
    Load the reticulate package library(reticulate)
    Activate the conda environment in R-studio use_condaenv('r-reticulate')
    Load the tensorflow libray library(tensorflow)
    Check if tensorflow is active tf$constant("Hellow Tensorflow")
>> (2)不安装虚拟环境,直接在conda 的 base 环境下,pip install tensorflow
在RStudio中,install.packages(tensorflow)    library(tensorflow)    install_tensorflow()会出现Error: could not find a Python environment for C:/Users/Admin/AppData/Local/r-miniconda/python.exe 错误。但是, R代码能正常运行。

>>>>!!!!如果以上都试过了,还不行。重新安装R,再按以上步骤操作!!!



https://m.sciencenet.cn/blog-331295-1310654.html

上一篇:中国雨水情 全国地表水水质自动下载的R实现
下一篇:R语言randomForest包的随机森林分类模型以及对重要变量的选择(修改)

0

该博文允许注册用户评论 请点击登录 评论 (1 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-24 00:30

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部