Skip to content

Cannot access GPU with Tensorflow on MacOS #620

@che25

Description

@che25

I would like to run Tensorflow on the GPUs of my Mac through RStudio.

library(tensorflow)
library(keras)
tf$config$list_logical_devices('GPU')

The return value is an empty list.
list()

For the CPU the return value is non-empty.

I have successfully installed tensorflow, and have also tried the development version

# install the development version of packages, in case the
# issue is already fixed but not on CRAN yet.
install.packages("pak")
pak::pak(sprintf("rstudio/%s", c("reticulate", "tensorflow", "keras")))
if (is.null(reticulate::virtualenv_starter()))
   reticulate::install_python()
tensorflow::install_tensorflow()

This runs

tensorflow::as_tensor("Hello World")

/Users/cedlich/.virtualenvs/r-tensorflow/lib/python3.9/site-packages/urllib3/init.py:35: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: urllib3/urllib3#3020
warnings.warn(
tf.Tensor(b'Hello World', shape=(), dtype=string)

Diagnostics

reticulate::py_config()
tensorflow::tf_config()
reticulate::import("tensorflow")
reticulate::py_last_error()
sessionInfo()

python: /Users/cedlich/.virtualenvs/r-tensorflow/bin/python
libpython: /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/config-3.9-darwin/libpython3.9.dylib
pythonhome: /Users/cedlich/.virtualenvs/r-tensorflow:/Users/cedlich/.virtualenvs/r-tensorflow
version: 3.9.6 (default, Feb 3 2024, 15:58:27) [Clang 15.0.0 (clang-1500.3.9.4)]
numpy: /Users/cedlich/.virtualenvs/r-tensorflow/lib/python3.9/site-packages/numpy
numpy_version: 2.0.2
tensorflow: /Users/cedlich/.virtualenvs/r-tensorflow/lib/python3.9/site-packages/tensorflow

NOTE: Python version was forced by import("tensorflow")

tensorflow::tf_config()
TensorFlow v2.18.1 (/.virtualenvs/r-tensorflow/lib/python3.9/site-packages/tensorflow)
Python v3.9 (
/.virtualenvs/r-tensorflow/bin/python)
reticulate::import("tensorflow")
Module(tensorflow)
reticulate::py_last_error()
NULL
sessionInfo()
R version 4.4.3 (2025-02-28)
Platform: aarch64-apple-darwin20
Running under: macOS Sonoma 14.2.1

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/Berlin
tzcode source: internal

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] keras_2.15.0 tensorflow_2.16.0.9000

loaded via a namespace (and not attached):
[1] R6_2.6.1 base64enc_0.1-3 Matrix_1.7-2 lattice_0.22-6 reticulate_1.41.0.9001
[6] magrittr_2.0.3 rappdirs_0.3.3 generics_0.1.3 png_0.1-8 lifecycle_1.0.4
[11] ps_1.9.0 cli_3.6.4 processx_3.8.6 pak_0.8.0.1 grid_4.4.3
[16] zeallot_0.1.0 withr_3.0.2 tfruns_1.5.3 compiler_4.4.3 rprojroot_2.0.4
[21] here_1.0.1 rstudioapi_0.17.1 tools_4.4.3 whisker_0.4.1 Rcpp_1.0.14
[26] rlang_1.1.5 jsonlite_1.9.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions