Tensorflow installation in RStudio Cloud does not work

I have been trying to install keras and tensorflow into my RStudioCloud over the past few days. Seems to not be working. The error messages that I have got are "Error: Error installing package(s): 'tensorflow==2.5'" and "Killed
Error: Error installing package(s): 'tensorflow==2.5', 'keras', 'tensorflow-hub', 'requests', 'Pillow', 'h5py', 'pyyaml'". Everything goes well until install_keras(). I am also on the premium version of RStudio Cloud so it's not really a space thing. My code is attached below:

install.packages('reticulate')
install.packages('keras')
library(reticulate)
library(keras)
virtualenv_create("myenv")
use_virtualenv("myenv", required = TRUE)
install_keras(method="virtualenv", envname="myenv")

It turns out that by default python's pip needs just under 3 GB RAM in order to be able to install tensorflow :scream:
You can increase the RAM to 3GB for the installation, or you can work around this by adding an option --no-cache-dir to pip like this:

install_keras(method="virtualenv", envname="myenv", pip_options = "--no-cache-dir")

You sir, are a genius. In fact, not only did your code work, it helped show me what was the problem with my code - I hadn't adjusted the memory allocated to me when I switched to the paid RStudio Cloud version. It runs either with the --no-cache-dir option or by increasing memory (of course, this option eats into your project hours).

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.