Repository navigation
Installation Issue - no valid installation of tensorflow #622
Description
Activity
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")
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
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")
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 variableTF_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 variableTF_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
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.Do you mean the original error?
I think the work around version is allowing me to use it OK.
Thanks,
Lynsey
Sorry, I posted the above for others that come across this, (including future me).
Please continue to use theexclude_newerworkaround.
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