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

trouble installing Tensorflow #1380

Closed
hmei617 opened this issue Oct 10, 2023 · 6 comments
Closed

trouble installing Tensorflow #1380

hmei617 opened this issue Oct 10, 2023 · 6 comments

Comments

@hmei617
Copy link

hmei617 commented Oct 10, 2023

I tried installed keras in R Studio with the following command but it's not working
install.packages("remotes")
remotes::install_github(sprintf("rstudio/%s", c("reticulate", "tensorflow", "keras")))
reticulate::miniconda_uninstall() # start with a blank slate
reticulate::install_miniconda()
keras::install_keras()

Everything seems to run fine until it get to the end where it tries to activate Tensorflow
C:\Windows>conda.bat activate "r-tensorflow"

(r-tensorflow) C:\Windows>"C:\Users\username\AppData\Local\r-miniconda\envs\r-tensorflow/python.exe" -m pip install --upgrade --no-user "tensorflow==2.13." tensorflow-hub tensorflow-datasets scipy requests Pillow h5py pandas pydot
ERROR: Could not find a version that satisfies the requirement tensorflow==2.13.
(from versions: none)
ERROR: No matching distribution found for tensorflow==2.13.*
Error: Error installing package(s): ""tensorflow==2.13.*"", "tensorflow-hub", "tensorflow-datasets", "scipy", "requests", "Pillow", "h5py", "pandas", "pydot"
In addition: Warning message:
In shell(fi, intern = intern) :
'C:\Users\username\AppData\Local\Temp\Rtmp48SVbE\file42883a5158b2.bat' execution failed with error code 1

I also noticed the version of the python.exe installed in C:\Users\users\AppData\Local\r-miniconda\envs\r-tensorflow
is version 3.12.0 which i read is not compatible with tensorflow

Below is the output from the following codes
reticulate::py_config()
tensorflow::tf_config()
reticulate::import("tensorflow")
reticulate::py_last_error()
sessionInfo()

reticulate::py_config()
python: C:/Users/username/AppData/Local/r-miniconda/envs/r-reticulate/python.exe
libpython: C:/Users/username/AppData/Local/r-miniconda/envs/r-reticulate/python39.dll
pythonhome: C:/Users/username/AppData/Local/r-miniconda/envs/r-reticulate
version: 3.9.18 | packaged by conda-forge | (main, Aug 30 2023, 03:40:31) [MSC v.1929 64 bit (AMD64)]
Architecture: 64bit
numpy: C:/Users/username/AppData/Local/r-miniconda/envs/r-reticulate/Lib/site-packages/numpy
numpy_version: 1.26.0
Warning messages:
1: In normalizePath(path.expand(path), winslash, mustWork) :
path[1]="\bos-700-11": The specified path is invalid
2: In normalizePath(path.expand(path), winslash, mustWork) :
path[1]="\bos-700-11": The specified path is invalid
tensorflow::tf_config()
Valid installation of TensorFlow not found.

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

Python exception encountered:
Traceback (most recent call last):
File "C:\Users\username\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 119, in _find_and_load_hook
return _run_hook(name, _hook)
File "C:\Users\username\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 93, in _run_hook
module = hook()
File "C:\Users\username\AppData\Local\R\win-library\4.3\reticulate\python\rpytools\loader.py", line 117, in _hook
return find_and_load(name, import)
ModuleNotFoundError: No module named 'tensorflow'

You can install TensorFlow using the install_tensorflow() function.

Warning message:
ModuleNotFoundError: No module named 'tensorflow'
Run reticulate::py_last_error() for details.
Restart the R session and load the tensorflow R package before reticulate has initialized Python, or ensure reticulate initialized a Python installation where the tensorflow module is installed.

reticulate::import("tensorflow")
Error in py_module_import(module, convert = convert) :
ModuleNotFoundError: No module named 'tensorflow'
Run reticulate::py_last_error() for details.

i would appreciate if someone could provide feedback on why it not installing. I've been working on this for days and not making any progress. thank you

@t-kalinowski
Copy link
Member

Hi, sorry you're having issues. We no longer recommend using miniconda, and now recommend using a virtual environment. Can you please follow the instructions in the "Installation Issue" template and report back?
https://github.com/rstudio/keras/blob/main/.github/ISSUE_TEMPLATE/installation-issue.md

@t-kalinowski t-kalinowski added the awaiting response Waiting for issue author to respond label Oct 13, 2023
Copy link

Automatically closed because there has not been a response for 30 days. When you're ready to work on this further, please comment here and the issue will automatically reopen.

@hschnack
Copy link

hschnack commented Dec 7, 2023

Hi, I am experiencing the same installation problem with install_keras().
I work on a MacBook M3 Pro, Sonoma 14.1.1
After trying the installation procedure I have used before, I tried the installation procedure you mentioned above, but install_keras() gives the same error:

  • /Users/F102073/.virtualenvs/r-tensorflow/bin/python -m pip install --upgrade --no-user 'tensorflow==2.13.' tensorflow-hub tensorflow-datasets scipy requests Pillow h5py pandas pydot
    ERROR: Could not find a version that satisfies the requirement tensorflow==2.13.
    (from versions: none)
    ERROR: No matching distribution found for tensorflow==2.13.*
    Error: Error installing package(s): "'tensorflow==2.13.*'", "tensorflow-hub", "tensorflow-datasets", "scipy", "requests", "Pillow", "h5py", "pandas", "pydot"

Please find below the output of the diagnostic commands you asked for. Thanks for your help!

reticulate::py_config()
python: /Users/F102073/.virtualenvs/r-tensorflow/bin/python
libpython: /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/config-3.12-darwin/libpython3.12.dylib
pythonhome: /Users/F102073/.virtualenvs/r-tensorflow:/Users/F102073/.virtualenvs/r-tensorflow
version: 3.12.0 (v3.12.0:0fb18b02c8, Oct 2 2023, 09:45:56) [Clang 13.0.0 (clang-1300.0.29.30)]
numpy: [NOT FOUND]
tensorflow: [NOT FOUND]

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

tensorflow::tf_config()
Valid installation of TensorFlow not found.

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

Python exception encountered:
Traceback (most recent call last):
File "/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/reticulate/python/rpytools/loader.py", 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/loader.py", line 93, in _run_hook
module = hook()
^^^^^^
File "/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/reticulate/python/rpytools/loader.py", line 117, in _hook
return find_and_load(name, import)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'tensorflow'

You can install TensorFlow using the install_tensorflow() function.

reticulate::import("tensorflow")
Error in py_module_import(module, convert = convert) :
ModuleNotFoundError: No module named 'tensorflow'
Run reticulate::py_last_error() for details.

reticulate::py_last_error()

── Python Exception Message ──────────────────────────────────────────────────────────────────────────
Traceback (most recent call last):
File "/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/reticulate/python/rpytools/loader.py", 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/loader.py", line 93, in _run_hook
module = hook()
^^^^^^
File "/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/reticulate/python/rpytools/loader.py", line 117, in _hook
return find_and_load(name, import)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'tensorflow'

── R Traceback ───────────────────────────────────────────────────────────────────────────────────────

  1. └─reticulate::import("tensorflow")
  2. └─reticulate:::py_module_import(module, convert = convert)

sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.1.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.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.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/Amsterdam
tzcode source: internal

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

loaded via a namespace (and not attached):
[1] R6_2.5.1 base64enc_0.1-3 Matrix_1.6-1.1 lattice_0.21-9
[5] reticulate_1.34.0.9000 magrittr_2.0.3 rappdirs_0.3.3 keras_2.13.0.9000
[9] remotes_2.4.2.1 generics_0.1.3 png_0.1-8 lifecycle_1.0.4
[13] cli_3.6.1 tensorflow_2.14.0.9000 grid_4.3.2 zeallot_0.1.0
[17] tfruns_1.5.1 compiler_4.3.2 rprojroot_2.0.4 here_1.0.1
[21] rstudioapi_0.15.0 tools_4.3.2 whisker_0.4.1 Rcpp_1.0.11
[25] rlang_1.1.2 jsonlite_1.8.8

@github-actions github-actions bot removed the awaiting response Waiting for issue author to respond label Dec 7, 2023
@github-actions github-actions bot reopened this Dec 7, 2023
@t-kalinowski
Copy link
Member

Python 3.12 is too new for the current release of Tensorflow. Please install an older version of Python:

reticulate::install_python("3.10:latest")
keras::install_keras(python_version = "3.10")

@t-kalinowski t-kalinowski added the awaiting response Waiting for issue author to respond label Dec 7, 2023
@hschnack
Copy link

hschnack commented Dec 8, 2023

Thanks @t-kalinowski, now it works!
I guess I could have found these versions requirements somewhere.
It was, however, from the initial error message, not clear to me that it was a version mismatch issue between python and tensorflow.

@github-actions github-actions bot removed the awaiting response Waiting for issue author to respond label Dec 8, 2023
@t-kalinowski
Copy link
Member

Glad the fix worked! We'll improve the error message for the next release.

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