Error with connecting to tensorflow and keras directory in R

Viewed 209

I am using R4.0.1 and Rstudio1.3.959 on windows 10. I have installed tensor flow and keras as follows:

install.packages("tensorflow")
install.packages("keras")
library(tensorflow)
library(keras)

I then installed Anaconda 64bit on my windows. Using conda prompt I installed tensorflow as follows:

conda create -n env_name python=3.6 tensorflow #tensorflow 2.2.0 was installed

I activated the environment as:

conda activate env_name

After that I forced R to use conda env_name using:

library(reticulate)
use_condaenv(condaenv = "env_name",required = T)

However I received following errors:

ERROR: The requested version of Python
('C:\Users\user\anaconda3\envs\env_name\python.exe') cannot be used, as
another version of Python
('C:/Users/user/AppData/Local/r-miniconda/envs/r-reticulate/python.exe')
has already been initialized. Please restart the R session if you need
to attach reticulate to a different version of Python.
Error in use_python(python, required = required) : 
  failed to initialize requested version of Python

I restarted the R session again run the code

library(reticulate)
use_condaenv(condaenv = "env_name",required = T)

However it gives the same error.

There are two directories which are really confusing me:

  1. Directory 1: 'C:/Users/user/AppData/Local/r-miniconda/envs/r-reticulate/python.exe'

  2. Directory 2: 'C:\Users\user\anaconda3\envs\env_name\python.exe'

Although I have installed tensorflow in directory 2, by default directory 1 is initialised.

Also following message is displayed

tf_config() #tensorflow configuration (e.g. version)
Installation of TensorFlow not found.

Python environments searched for 'tensorflow' package:
 C:\Users\user\AppData\Local\r-miniconda\envs\r-reticulate\python.exe

Is it possible to install tensorflow and keras in directory 1? If so how to install it? Will it work?

For your information, earlier i had no problem running Keras_model_sequential() with tensorflow and keras. It worked well from directory 2. It is just recent that I am facing this issues.

Please help me how to resolve this issue.

0 Answers
Related