Skip to content

Installation Issue: 'r-tensorflow' exists but is not a virtual environment #584

@candelas762

Description

@candelas762

I saw that there is a similar posted issue ( #522 ) but I tried to follow it and it did not solve my error.

I also tried the suggested procedure when you open a new Installation Issue and still not fixed.

After running the first snippet:

# 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()
keras::install_keras()

I get the error at:

> keras::install_keras()
Error in virtualenv_install(envname = envname, packages = packages, ignore_installed = pip_ignore_installed,  : 
  'r-tensorflow' exists but is not a virtual environment

After running the second snippet I get:

> tensorflow::as_tensor("Hello World")
Error: Valid installation of TensorFlow not found.

Python environments searched for 'tensorflow' package:
 C:\Users\jaca\OneDrive - Norwegian University of Life Sciences\Documents\.virtualenvs\r-reticulate\Scripts\python.exe

Python exception encountered:
 Traceback (most recent call last):
  File "C:\Users\jaca\AppData\Local\R\win-library\4.2\reticulate\python\rpytools\loader.py", line 119, in _find_and_load_hook
    return _run_hook(name, _hook)
  File "C:\Users\jaca\AppData\Local\R\win-library\4.2\reticulate\python\rpytools\loader.py", line 93, in _run_hook
    module = hook()
  File "C:\Users\jaca\AppData\Local\R\win-library\4.2\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.
In addition: Warning message:
In Sys.setlocale("LC_CTYPE", ctype) :
  OS reports request to set locale to "Norwegian Bokmål_Norway.utf8" cannot be honored

After running the third snippet I get:

> reticulate::py_config()
python:         C:/Users/jaca/OneDrive - Norwegian University of Life Sciences/Documents/.virtualenvs/r-reticulate/Scripts/python.exe
libpython:      C:/Users/jaca/AppData/Local/r-reticulate/r-reticulate/pyenv/pyenv-win/versions/3.9.13/python39.dll
pythonhome:     C:/Users/jaca/OneDrive - Norwegian University of Life Sciences/Documents/.virtualenvs/r-reticulate
version:        3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:/Users/jaca/OneDrive - Norwegian University of Life Sciences/Documents/.virtualenvs/r-reticulate/Lib/site-packages/numpy
numpy_version:  1.26.0
tensorflow:     [NOT FOUND]
> tensorflow::tf_config()
Valid installation of TensorFlow not found.

Python environments searched for 'tensorflow' package:
 C:\Users\jaca\OneDrive - Norwegian University of Life Sciences\Documents\.virtualenvs\r-reticulate\Scripts\python.exe

Python exception encountered:
 Traceback (most recent call last):
  File "C:\Users\jaca\AppData\Local\R\win-library\4.2\reticulate\python\rpytools\loader.py", line 119, in _find_and_load_hook
    return _run_hook(name, _hook)
  File "C:\Users\jaca\AppData\Local\R\win-library\4.2\reticulate\python\rpytools\loader.py", line 93, in _run_hook
    module = hook()
  File "C:\Users\jaca\AppData\Local\R\win-library\4.2\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 "C:\Users\jaca\AppData\Local\R\win-library\4.2\reticulate\python\rpytools\loader.py", line 119, in _find_and_load_hook
    return _run_hook(name, _hook)
  File "C:\Users\jaca\AppData\Local\R\win-library\4.2\reticulate\python\rpytools\loader.py", line 93, in _run_hook
    module = hook()
  File "C:\Users\jaca\AppData\Local\R\win-library\4.2\reticulate\python\rpytools\loader.py", line 117, in _hook
    return _find_and_load(name, import_)
ModuleNotFoundError: No module named 'tensorflow'

-- R Traceback -------------------------------------------------------------------------------------------------------
    x
 1. \-reticulate::import("tensorflow")
 2.   \-reticulate:::py_module_import(module, convert = convert)
> sessionInfo()
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server x64 (build 20348)

Matrix products: default

locale:
[1] C
system code page: 65001

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

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.11            here_1.0.1             lattice_0.20-45        png_0.1-8             
 [5] pak_0.6.0              rprojroot_2.0.3        withr_2.5.1            zeallot_0.1.0         
 [9] rappdirs_0.3.3         grid_4.2.2             R6_2.5.1               lifecycle_1.0.3       
[13] jsonlite_1.8.7         magrittr_2.0.3         tfruns_1.5.1           rlang_1.1.1           
[17] cli_3.6.1              rstudioapi_0.15.0      whisker_0.4.1          Matrix_1.5-1          
[21] generics_0.1.3         reticulate_1.32.0.9002 keras_2.13.0.9000      tools_4.2.2           
[25] compiler_4.2.2         base64enc_0.1-3        tensorflow_2.14.0.9000

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