Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to install tensor-flow in R-Studio on m1 mac #530

Closed
pmgarafola opened this issue May 7, 2022 · 8 comments
Closed

Unable to install tensor-flow in R-Studio on m1 mac #530

pmgarafola opened this issue May 7, 2022 · 8 comments

Comments

@pmgarafola
Copy link

Hello - I can't seem to get tensor-flow working on my m1 mac. I wonder if it's a pathing problem or I have the tensor-flow mac-os library installed in the wrong place?

Thanks in advance for your help.

Mac Version: macOS Monterey, version 12.3.1

This is my R-version:

version
_
platform aarch64-apple-darwin20
arch aarch64
os darwin20
system aarch64, darwin20
status
major 4
minor 2.0
year 2022
month 04
day 22
svn rev 82229
language R
version.string R version 4.2.0 (2022-04-22)
nickname Vigorous Calisthenics

Performed the follwing steps in R-studio R script:

install.packages("remotes")
remotes::install_github(sprintf("rstudio/%s", c("reticulate", "tensorflow", "keras")))
reticulate::miniconda_uninstall()

start with a blank slate

reticulate::install_miniconda(force=TRUE)
keras::install_keras()

Everything worked up until the last step. Here is the error message:

keras::install_keras()
Installing: pandas, Pillow, pydot

  • '/Users/petergarafola/Library/r-miniconda-arm64/bin/conda' 'install' '--yes' '--prefix' '/usr/local/bin' '-c' 'conda-forge' 'pandas' 'Pillow' 'pydot'
    Collecting package metadata (current_repodata.json): ...working... done
    Solving environment: ...working... done

All requested packages already installed.

Installing: tensorflow-deps

  • '/Users/petergarafola/Library/r-miniconda-arm64/bin/conda' 'install' '--yes' '--prefix' '/usr/local/bin' '-c' 'apple' '-c' 'conda-forge' 'tensorflow-deps'
    Collecting package metadata (current_repodata.json): ...working... done
    Solving environment: ...working... done

All requested packages already installed.

Installing: tensorflow-macos

  • . /Users/petergarafola/Library/r-miniconda-arm64/bin/activate
  • conda activate '/usr/local/bin'
  • '/usr/local/bin/bin/python' -m pip install --upgrade 'tensorflow-macos'
    ERROR: Could not find a version that satisfies the requirement tensorflow-macos (from versions: none)
    ERROR: No matching distribution found for tensorflow-macos
    Error: Error installing package(s): "'tensorflow-macos'"

Path environment variable:
/Users/petergarafola/miniforge3/bin:/Users/petergarafola/miniforge3/condabin:/opt/homebrew/bin:/opt/homebrew/sbin:/Library/Frameworks/Python.framework/Versions/3.10/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin

@pmgarafola
Copy link
Author

Update - still not working but closer.

I repeated the install steps from scratch. Went into R- Studio and selected R Studio->Preferences->Python. Picked the Python 3.8.9 [System Interpreter] option. Then repeated the tensorflow::install_tensorflow() command. This time it seemed to work and did not give any error messages.

However after loading the keras reticulate, and tensorflow libraries, and then making a call to keras_model_sequential, I get the following:

modelLr = keras_model_sequential()
List of 20
$ python : chr "/usr/bin/python3"
$ libpython : chr "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/config-3.8-"| truncated
$ pythonhome : chr "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8:/Library/Developer/Comman"| truncated
$ pythonpath : chr "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python38.zip:/Library"| truncated
$ prefix : chr "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8"
$ exec_prefix : chr "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8"
$ base_exec_prefix : chr "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8"
$ virtualenv : chr ""
$ virtualenv_activate : chr ""
$ version_string : chr "3.8.9 (default, Mar 30 2022, 13:51:16) [Clang 13.1.6 (clang-1316.0.21.2.3)]"
$ version : chr "3.8"
$ architecture : chr "64bit"
$ anaconda : logi FALSE
$ conda : logi FALSE
$ numpy : NULL
$ required_module : chr "tensorflow"
$ required_module_path: NULL
$ available : logi TRUE
$ python_versions : chr "/usr/bin/python3"
$ forced : chr "use_python function"

  • attr(*, "class")= chr "py_config"
    Error: Python module tensorflow.keras was not found.

Detected Python configuration:

@njtierney
Copy link

Wanted to add that I cannot install Tensorflow on an M1 mac at the moment, I'm not sure what has changed, as I used to be able to do this with no issues.

Here's my reprex + session info:

library(tensorflow)
install_tensorflow(envname = "greta-env")
#> Installing: tensorflow-deps==2.6
#> Error: one or more Python packages failed to install [error code 1]

Created on 2022-05-11 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.0 (2022-04-22)
#>  os       macOS Big Sur 11.2.2
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_AU.UTF-8
#>  ctype    en_AU.UTF-8
#>  tz       Australia/Perth
#>  date     2022-05-11
#>  pandoc   2.17.1.1 @ /Applications/RStudio.app/Contents/MacOS/quarto/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date (UTC) lib source
#>  base64enc     0.1-3      2015-07-28 [1] CRAN (R 4.2.0)
#>  cli           3.3.0      2022-04-25 [1] CRAN (R 4.2.0)
#>  digest        0.6.29     2021-12-01 [1] CRAN (R 4.2.0)
#>  evaluate      0.15       2022-02-18 [1] CRAN (R 4.2.0)
#>  fastmap       1.1.0      2021-01-25 [1] CRAN (R 4.2.0)
#>  fs            1.5.2      2021-12-08 [1] CRAN (R 4.2.0)
#>  glue          1.6.2      2022-02-24 [1] CRAN (R 4.2.0)
#>  highr         0.9        2021-04-16 [1] CRAN (R 4.2.0)
#>  htmltools     0.5.2      2021-08-25 [1] CRAN (R 4.2.0)
#>  jsonlite      1.8.0      2022-02-22 [1] CRAN (R 4.2.0)
#>  knitr         1.39       2022-04-26 [1] CRAN (R 4.2.0)
#>  lattice       0.20-45    2021-09-22 [1] CRAN (R 4.2.0)
#>  magrittr      2.0.3      2022-03-30 [1] CRAN (R 4.2.0)
#>  Matrix        1.4-1      2022-03-23 [1] CRAN (R 4.2.0)
#>  png           0.1-7      2013-12-03 [1] CRAN (R 4.2.0)
#>  Rcpp          1.0.8.3    2022-03-17 [1] CRAN (R 4.2.0)
#>  reprex        2.0.1      2021-08-05 [1] CRAN (R 4.2.0)
#>  reticulate    1.24       2022-01-26 [1] CRAN (R 4.2.0)
#>  rlang         1.0.2      2022-03-04 [1] CRAN (R 4.2.0)
#>  rmarkdown     2.14       2022-04-25 [1] CRAN (R 4.2.0)
#>  rstudioapi    0.13       2020-11-12 [1] CRAN (R 4.2.0)
#>  sessioninfo   1.2.2      2021-12-06 [1] CRAN (R 4.2.0)
#>  stringi       1.7.6      2021-11-29 [1] CRAN (R 4.2.0)
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 4.2.0)
#>  tensorflow  * 2.8.0.9000 2022-05-11 [1] Github (rstudio/tensorflow@6e3e00e)
#>  tfruns        1.5.0      2021-02-26 [1] CRAN (R 4.2.0)
#>  whisker       0.4        2019-08-28 [1] CRAN (R 4.2.0)
#>  withr         2.5.0      2022-03-03 [1] CRAN (R 4.2.0)
#>  xfun          0.31       2022-05-10 [1] CRAN (R 4.2.0)
#>  yaml          2.3.5      2022-02-21 [1] CRAN (R 4.2.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Not all of the error message was captured above, so here is what I get when I run the above code:

> tensorflow::install_tensorflow(envname = "greta-env")
Installing: tensorflow-deps==2.6
Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.
Solving environment: ...working... failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): ...working... done
Solving environment: ...working... failed with initial frozen solve. Retrying with flexible solve.
                                                                                           
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed

UnsatisfiableError: The following specifications were found to be incompatible with each other:

Output in format: Requested package -> Available versions

Error: one or more Python packages failed to install [error code 1]

I've tried removing miniconda, and the greta-env environment variable, and I still don't get any progress than this.

@t-kalinowski
Copy link
Member

That's unfortunate, looks like an update to a conda package is causing the installation of a pinned tensorflow-macos to fail. I unfortunately don't have an older version of macOS to test on. Can you possibly upgrade to Monterey? Everything should work there.

@t-kalinowski
Copy link
Member

Quick update, I confirmed that this successfully installs TensorFlow on an M1 Mac running Monterey

remotes::install_github("rstudio/tensorflow")
reticulate::miniconda_uninstall()
reticulate::install_miniconda()
tensorflow::install_tensorflow()

@pmgarafola
Copy link
Author

I uninstalled the tensorflow and keras packages in R Studio and then re-installed tensorflow using the above commands. This works (i.e. keras and tensorflow library calls work) as long as there is nothing selected in the R Studio->Preferences->Python option. As soon as I select one of the available interpreters I get the error message below about tensorflow not being installed, even though it is definitely installed. It must be either a pathing issue or maybe I installed tensorflow wrong. I am hoping that this does not mean I will have similar issues with other python libraries, but I can use the tensorflow library for now. Thanks for the help.

Error: Valid installation of TensorFlow not found.

Python environments searched for 'tensorflow' package:
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10

Python exception encountered:
Traceback (most recent call last):
File "/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/reticulate/python/rpytools/loader.py", line 39, in _import_hook
module = _import(
ModuleNotFoundError: No module named 'tensorflow'

You can install TensorFlow using the install_tensorflow() function.

@t-kalinowski
Copy link
Member

Hi, I think it's working as intended. tensorflow::install_tensorflow() installs the Python 'tensorflow' package into a single specific Python installation. Any given computer may have multiple Python installations, and if you want to use Tensorflow with some other Python installation (not the default "r-reticulate" conda environment in the r-miniconda Python installation reticulate bootstraps), you'll have to point tensorflow::install_tensorflow() at it, e.g, by passing a valid value to envname.

@pmgarafola
Copy link
Author

How does the install select a python installation if you don't specify an environment? Or are you saying that the install creates a python installation for tensorflow to use?

As I mentioned, I have it working so am closing the issue. Thanks for the help.

@t-kalinowski
Copy link
Member

install_miniconda() creates a python installation ("r-miniconda" under rappdirs::user_data_dir()), and also creates a conda environment with that installation named r-reticulate. Subsequently, reticulate::py_install() selects the r-reticulate conda environment as the default, if you've taken no explicit action opting to use another Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants