Can't install tensorflow per quickstart documentation

I am following the 'Quick start' instructions on the website: TensorFlow for R - Quick start (copied below) and the installation fails with:

tensorflow::as_tensor("Hello World")
Error: Valid installation of TensorFlow not found.

Python environments searched for 'tensorflow' package:

Python exception encountered:
Traceback (most recent call last):
File "/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/reticulate/python/rpytools/", line 119, in _find_and_load_hook
return _run_hook(name, _hook)
File "/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/reticulate/python/rpytools/", line 93, in _run_hook
module = hook()
File "/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/reticulate/python/rpytools/", line 117, in _hook
return find_and_load(name, import)
ModuleNotFoundError: No module named 'tensorflow'

You can install TensorFlow using the install_tensorflow() function.

My system is MacBook M1 running the latest OS: 13.4.1 (c) (22F770820d). I did a fresh install of RStudio: Version 2023.06.1+524 (2023.06.1+524)

The full installation documentation from the website (URL above) is:

Quick start

Prior to using the tensorflow R package you need to install a version of Python and TensorFlow on your system. Below we describe how to install to do this as well the various options available for customizing your installation.

Note that this article principally covers the use of the R install_tensorflow() function, which provides an easy to use wrapper for the various steps required to install TensorFlow. You can also choose to install TensorFlow manually (as described at TensorFlow 2 را نصب کنید). In that case the Custom Installation section covers how to arrange for the tensorflow R package to use the version you installed.

TensorFlow is tested and supported on the following 64-bit systems:

  • Ubuntu 20.04 or later
  • Windows 10 or later
  • macOS 11 (Big Sur) or later (Intel or M1)


First, install the tensorflow R package from GitHub as follows:


Next, configure R with a Python installation it can use, like this:

path_to_python <- install_python()
virtualenv_create("r-reticulate", python = path_to_python)

Note that if you already have Python installed, you don’t need to call install_python() and instead can just supply an absolute path to the Python executable.

Then, use the install_tensorflow() function to install TensorFlow.

install_tensorflow(envname = "r-reticulate")

You can also use keras::install_keras(), which installes Tensorflow, in addition to some commonly used packages like “scipy” and “tensorflow-datasets”.

install_keras(envname = "r-reticulate")

You can confirm that the installation succeeded with:

tf$constant("Hello Tensorflow!")
Loaded Tensorflow version 2.10.0
tf.Tensor(b'Hello Tensorflow!', shape=(), dtype=string)

This will provide you with a default installation of TensorFlow suitable for use with the tensorflow R package. Read on if you want to learn about additional installation options, including installing a version of TensorFlow that takes advantage of Nvidia GPUs if you have the correct CUDA libraries installed.

The Rstudio option to "Automatically activate project-local Python environments" may be interfering with reticulate finding the correct tensorflow environment.

Make sure the option to "Automatically activate project-local Python environments" is unset.
Then, a simple call to keras::install_keras() or tensorflow::install_tensorflow() should be sufficient.

Thanks for the reply. The checkbox had been checked so I un-checked it as you suggested.

Then trying: keras::install_keras() as suggested the same problem occurs.

Sadly, after following the quick start instructions the same problem occurs.

Any other suggestions?

Could there be any issues with Python or reticulate or environments?

This topic was automatically closed 21 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.