user5983006
user5983006

Reputation: 139

Nightmare of installing and running Tensorflow in R Studio on windows 10

Please, I have been having trouble for weeks now trying to install and run tensorflow and keras in R Studio. I have tried everything I can find online to no avail. I have anaconda installed on my system, do I need to uninstall it? After running this line of code:

install_tensorflow(method = "conda",version = "default", envname = "py3.6",
                   conda_python_version = "3.6",
                   extra_packages = c("matplotlib","numpy","pandas","scikit-learn"))
install_keras(method = "conda")

It says installation successful, but when I now run tf$constant("Hellow Tensorflow") I get the following error message:

Error: Installation of TensorFlow not found.

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

You can install TensorFlow using the install_tensorflow() function.

I also try to install keras using:

install_keras(method = "conda")
install_keras(tensorflow = "default")

But I also get an error message:

Error in install_keras(method = "conda") : 
  You should call install_keras() only in a fresh R session that has not yet initialized Keras and TensorFlow (this is to avoid DLL in use errors during installation)

I also have reticulate installed in R Studio. I honestly do not know why it is such a task to install and run tensorflow in R for windows 10. I have been on it for weeks without any tangible headway. Please, as always I will be extremely grateful if someone can help me resolve this nagging issue

Upvotes: 3

Views: 4316

Answers (2)

Afshin
Afshin

Reputation: 133

If you are working in a project environment in RStudio, I suggest closing the project using Close Project option in the upper-right slider in RStudio. Make sure you have installed Python on your system and try the following codes (change Username based on the user name of your system):

library(keras)
library(tensorflow)
library(reticulate)
path_to_python <- "C:/Users/Username/AppData/Local/Programs/Python/Python310"
virtualenv_create("r-reticulate", python = path_to_python)
install_tensorflow(envname = "r-reticulate")
install_keras(envname = "r-reticulate")
use_virtualenv("r-reticulate")

I hope it works.

Upvotes: 0

t-kalinowski
t-kalinowski

Reputation: 1515

there have been significant changes to the installation pathway in the R package recently. Can you please try the following (in a fresh R session):

install.packages("keras")
reticulate::install_miniconda()
keras::install_keras()

If the above doesn't work, can you please file an issue: https://github.com/rstudio/keras/issues/new

Upvotes: 3

Related Questions