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

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

Closed
candelas762 opened this issue Oct 3, 2023 · 8 comments

Comments

@candelas762
Copy link

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
@t-kalinowski
Copy link
Member

t-kalinowski commented Oct 3, 2023

That error is raised if the virtualenv directory is missing certain files that indicate it is indeed a venv. In particular: here and here

keras::install_keras() should remove any pre-existing environment named "r-tensorflow", so something is likely going wrong w/ the venv creation and there is a good chance we'll see what's wrong in the output from install_keras(). Can you please copy-paste the full output from running install_keras()?

My suspicion is that this is due to the venv being on a OneDrive managed location, and that somehow interferes with file deletion or creation. I recommend changing the default location for virtualenvs by setting the envvar WORKON_HOME to a directory local to your machine. (either setting it system wide in system setting, or by placing something like this in .Renviron

WORKON_HOME=~/../.virtualenvs

@chaosssss123

This comment was marked as outdated.

@t-kalinowski
Copy link
Member

Please see the discussion in rstudio/keras3#1381

@chaosssss123

This comment was marked as off-topic.

@chaosssss123

This comment was marked as outdated.

@chaosssss123

This comment was marked as outdated.

@chaosssss123

This comment was marked as off-topic.

@chaosssss123

This comment was marked as off-topic.

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