Skip to content

Installation Issue - no valid installation of tensorflow #622

Description

@lynseymccoll

Hi,

I'm having problems installing tensorflow.

I can add the following code:

install_tensorflow(envname = "C:\Users\LynseyMcColl\AppData\Local\r-tensorflow", method = "conda", python_version = "3.11", version = "2.18")

Which says the installation is successful but when I then try it out I get the following error message:
Error: Valid installation of TensorFlow not found.

I have set an envname above as I am working on one drive and so have pointed it to the desktop rather than an online environment which I've read can cause problems.

I've put the messages I get to the commands requested below.

Many thanks,

Lynsey

reticulate::py_config()

libpython:      C:/Users/LynseyMcColl/AppData/Local/Programs/Python/Python311/python311.dll
pythonhome:     C:/Users/LynseyMcColl/AppData/Local/Programs/Python/Python311
version:        3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
Architecture:   64bit
numpy:           [NOT FOUND]

NOTE: Python version was forced by use_python() function

tensorflow::tf_config()

Valid installation of TensorFlow not found.

Python environments searched for 'tensorflow' package:
 C:\Users\LynseyMcColl\AppData\Local\Programs\Python\Python311\python.exe

Python exception encountered:
 Traceback (most recent call last):
  File "C:\Users\LynseyMcColl\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 122, in _find_and_load_hook
    return _run_hook(name, _hook)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\LynseyMcColl\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 96, in _run_hook
    module = hook()
             ^^^^^^
  File "C:\Users\LynseyMcColl\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 120, 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.

reticulate::py_last_error()

── Python Exception Message ──────────────────────────────────────────────────────────────────────────────────
Traceback (most recent call last):
  File "C:\Users\LynseyMcColl\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 122, in _find_and_load_hook
    return _run_hook(name, _hook)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\LynseyMcColl\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 96, in _run_hook
    module = hook()
             ^^^^^^
  File "C:\Users\LynseyMcColl\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 120, 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)
See `reticulate::py_last_error()$r_trace$full_call` for more details.

sessionInfo()

R version 4.4.3 (2025-02-28 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)

Matrix products: default


locale:
[1] LC_COLLATE=English_United Kingdom.utf8  LC_CTYPE=English_United Kingdom.utf8   
[3] LC_MONETARY=English_United Kingdom.utf8 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.utf8    

time zone: Europe/London
tzcode source: internal

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

loaded via a namespace (and not attached):
 [1] base64enc_0.1-3        Matrix_1.7-2           lattice_0.22-6         reticulate_1.42.0     
 [5] magrittr_2.0.3         glue_1.8.0             png_0.1-8              lifecycle_1.0.4       
 [9] cli_3.6.4              tensorflow_2.16.0.9000 vctrs_0.6.5            grid_4.4.3            
[13] tfruns_1.5.3           compiler_4.4.3         rstudioapi_0.17.1      tools_4.4.3           
[17] whisker_0.4.1          pillar_1.10.1          Rcpp_1.0.14            rlang_1.1.5           
[21] jsonlite_2.0.0   

Activity

  1. t-kalinowski commented on Apr 9, 2025

    @t-kalinowski
    Member

    What happens if you run the following:

    In a fresh R session:

    reticulate:::rm_all_reticulate_state()
    remotes::install_github("rstudio/tensorflow")

    And then, in another fresh R session:

    Sys.setenv("RETICULATE_PYTHON" = "managed")
    library(tensorflow)
    tf$constant("Hello World")
  2. lynseymccoll commented on Apr 10, 2025

    @lynseymccoll
    Author

    Thanks for getting back to me so quickly.

    Here is what I get:

    > reticulate:::rm_all_reticulate_state()
    > remotes::install_github("rstudio/tensorflow")
    Skipping install of 'tensorflow' from a github remote, the SHA1 (e48867f4) has not changed since last install.
      Use `force = TRUE` to force installation
    
    Restarting R session...
    
    
    > tf$constant("Hello World")
    Downloading cpython-3.11.12-windows-x86_64-none (24.3MiB)
     Downloaded cpython-3.11.12-windows-x86_64-none
    Downloading pygments (1.2MiB)
    Downloading h5py (2.8MiB)
    Downloading tensorflow-io-gcs-filesystem (1.4MiB)
    Downloading setuptools (1.2MiB)
    Downloading libclang (25.2MiB)
    Downloading numpy (15.1MiB)
    Downloading tensorflow (358.5MiB)
    Downloading grpcio (4.1MiB)
    Downloading keras (1.3MiB)
    Downloading tensorboard (5.2MiB)
     Downloaded tensorflow-io-gcs-filesystem
     Downloaded h5py
     Downloaded grpcio
     Downloaded pygments
     Downloaded setuptools
     Downloaded tensorboard
     Downloaded keras
     Downloaded numpy
     Downloaded libclang
     Downloaded tensorflow
    Installed 38 packages in 24.84s
    
    Error: Valid installation of TensorFlow not found.  Python environments searched for 'tensorflow' package:  C:\Users\LynseyMcColl\AppData\Local\R\cache\R\reticulate\uv\cache\archive-v0\yr1j5_ZBEj9Mt4o17V7_J\Scripts\python.exe  Python exception encountered:  Traceback (most recent call last):   File "C:\Users\LYNSEY~1\AppData\Local\R\cache\R\RETICU~1\uv\cache\ARCHIV~1\YR1J5_~1\Lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 73, in <module>     from tensorflow.python._pywrap_tensorflow_internal import *   File "C:\Users\LynseyMcColl\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 122, in _find_and_load_hook     return _run_hook(name, _hook)            ^^^^^^^^^^^^^^^^^^^^^^   File "C:\Users\LynseyMcColl\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 96, in _run_hook     module = hook()              ^^^^^^   File "C:\Users\LynseyMcColl\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 120, i
    --
    

    I'm sorry if I've done something strange with the installation.

    Lynsey

  3. t-kalinowski commented on Apr 10, 2025

    @t-kalinowski
    Member

    Thanks, I can reproduce the same error.
    There is something wrong with the recent TensorFlow builds for Windows that will take some investigation.

    For now you can workaround by adding a call to py_require(exclude_newer = ) before python has initialized:

    Sys.setenv("RETICULATE_PYTHON" = "managed")
    reticulate::py_require(exclude_newer = "2025-03-11")
    
    library(tensorflow)
    tf$constant("Hello World")
  4. lynseymccoll commented on Apr 10, 2025

    @lynseymccoll
    Author

    Yes I think this works now.

    I get:

    '''

    tf$constant("Hello World")
    2025-04-10 14:06:33.321594: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable TF_ENABLE_ONEDNN_OPTS=0.
    2025-04-10 14:06:35.051642: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable TF_ENABLE_ONEDNN_OPTS=0.
    2025-04-10 14:06:38.059908: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
    To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
    tf.Tensor(b'Hello World', shape=(), dtype=string)

    Thank you for reviewing and I hope the issue is easily fixed.

    Lynsey

  5. t-kalinowski commented on Apr 10, 2025

    @t-kalinowski
    Member

    This error seems to only happen in the RStudio IDE. I can't reproduce it in Rterm.exe

    minimal reprex:

    tensorflow::install_tensorflow()
    library(reticulate)
    tf <- import("tensorflow")
    tf$constant("Hello World")

    Produces:

    > library(reticulate)
    > tf <- import("tensorflow")
    Error in py_module_import(module, convert = convert) : 
      ImportError: Traceback (most recent call last):
      File "C:\Users\kalin\DOCUME~1\VIRTUA~1\R-TENS~1\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 70, in <module>
    <...truncated...>ppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 96, in _run_hook
        module = hook()
      File "C:\Users\kalin\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 120, in _hook
        return _find_and_load(name, import_)
    ImportError: DLL load failed while importing _pywrap_tensorflow_internal: A dynamic link library (DLL) initialization routine failed.
    
    
    Failed to load the native TensorFlow runtime.
    See https://www.tensorflow.org/install/errors for some common causes and solutions.
    If you need help, create an issue at https://github.com/tensorflow/tensorflow/issues and include the entire stack trace above this error message.
    Run `reticulate::py_last_error()` for details.
    
    > reticulate::py_last_error()
    
    ── Python Exception Message ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    Traceback (most recent call last):
      File "C:\Users\kalin\DOCUME~1\VIRTUA~1\R-TENS~1\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 70, in <module>
        from tensorflow.python._pywrap_tensorflow_internal import *
      File "C:\Users\kalin\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 122, in _find_and_load_hook
        return _run_hook(name, _hook)
      File "C:\Users\kalin\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 96, in _run_hook
        module = hook()
      File "C:\Users\kalin\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 120, in _hook
        return _find_and_load(name, import_)
    ImportError: DLL load failed while importing _pywrap_tensorflow_internal: A dynamic link library (DLL) initialization routine failed.
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:\Users\kalin\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 122, in _find_and_load_hook
        return _run_hook(name, _hook)
      File "C:\Users\kalin\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 96, in _run_hook
        module = hook()
      File "C:\Users\kalin\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 120, in _hook
        return _find_and_load(name, import_)
      File "C:\Users\kalin\DOCUME~1\VIRTUA~1\R-TENS~1\lib\site-packages\tensorflow\__init__.py", line 40, in <module>
        from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow  # pylint: disable=unused-import
      File "C:\Users\kalin\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 122, in _find_and_load_hook
        return _run_hook(name, _hook)
      File "C:\Users\kalin\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 96, in _run_hook
        module = hook()
      File "C:\Users\kalin\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 120, in _hook
        return _find_and_load(name, import_)
      File "C:\Users\kalin\DOCUME~1\VIRTUA~1\R-TENS~1\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 85, in <module>
        raise ImportError(
    ImportError: Traceback (most recent call last):
      File "C:\Users\kalin\DOCUME~1\VIRTUA~1\R-TENS~1\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 70, in <module>
        from tensorflow.python._pywrap_tensorflow_internal import *
      File "C:\Users\kalin\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 122, in _find_and_load_hook
        return _run_hook(name, _hook)
      File "C:\Users\kalin\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 96, in _run_hook
        module = hook()
      File "C:\Users\kalin\AppData\Local\R\win-library\4.4\reticulate\python\rpytools\loader.py", line 120, in _hook
        return _find_and_load(name, import_)
    ImportError: DLL load failed while importing _pywrap_tensorflow_internal: A dynamic link library (DLL) initialization routine failed.
    
    
    Failed to load the native TensorFlow runtime.
    See https://www.tensorflow.org/install/errors for some common causes and solutions.
    If you need help, create an issue at https://github.com/tensorflow/tensorflow/issues and include the entire stack trace above this error message.
    
    ── R Traceback ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
        ▆
     1. └─reticulate::import("tensorflow")
     2.   └─reticulate:::py_module_import(module, convert = convert)
    See `reticulate::py_last_error()$r_trace$full_call` for more details.
    
  6. lynseymccoll commented on Apr 10, 2025

    @lynseymccoll
    Author

    Do you mean the original error?

    I think the work around version is allowing me to use it OK.

    Thanks,

    Lynsey

  7. t-kalinowski commented on Apr 10, 2025

    @t-kalinowski
    Member

    Sorry, I posted the above for others that come across this, (including future me).
    Please continue to use the exclude_newer workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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