rstudio / tensorflow

TensorFlow for R
https://tensorflow.rstudio.com
Apache License 2.0
1.32k stars 317 forks source link

Installation Issue #597

Closed jobstdavid closed 1 month ago

jobstdavid commented 2 months ago

I followed you installation instructions and receive the following error messages:

pak::pak(sprintf("rstudio/%s", c("reticulate", "tensorflow", "keras")))
! Using bundled GitHub PAT. Please add your own PAT using `gitcreds::gitcreds_set()`.
✔ Loading metadata database ... done                           

ℹ No downloads are needed
✔ 3 pkgs + 31 deps: kept 32 [6s]
> if (is.null(reticulate::virtualenv_starter()))
+   reticulate::install_python()
Warning messages:
1: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[1]="/usr/local/bin/python3": No such file or directory
2: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[2]="/usr/local/bin/python3-config": No such file or directory
3: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[3]="/usr/local/bin/python3-intel64": No such file or directory
4: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[4]="/usr/local/bin/python3.10": No such file or directory
5: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[5]="/usr/local/bin/python3.10-config": No such file or directory
6: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[6]="/usr/local/bin/python3.10-intel64": No such file or directory
> tensorflow::install_tensorflow(restart_session = F)
Virtual environment 'r-tensorflow' removed.
Using Python: /Users/david/.pyenv/versions/3.10.14/bin/python3.10
Creating virtual environment 'r-tensorflow' ... 
+ /Users/david/.pyenv/versions/3.10.14/bin/python3.10 -m venv /Users/david/.virtualenvs/r-tensorflow
Done!
Installing packages: pip, wheel, setuptools
+ /Users/david/.virtualenvs/r-tensorflow/bin/python -m pip install --upgrade pip wheel setuptools
Requirement already satisfied: pip in /Users/david/.virtualenvs/r-tensorflow/lib/python3.10/site-packages (23.0.1)
Collecting pip
  Using cached pip-24.0-py3-none-any.whl (2.1 MB)
Collecting wheel
  Using cached wheel-0.43.0-py3-none-any.whl (65 kB)
Requirement already satisfied: setuptools in /Users/david/.virtualenvs/r-tensorflow/lib/python3.10/site-packages (65.5.0)
Collecting setuptools
  Using cached setuptools-69.5.1-py3-none-any.whl (894 kB)
Installing collected packages: wheel, setuptools, pip
  Attempting uninstall: setuptools
    Found existing installation: setuptools 65.5.0
    Uninstalling setuptools-65.5.0:
      Successfully uninstalled setuptools-65.5.0
  Attempting uninstall: pip
    Found existing installation: pip 23.0.1
    Uninstalling pip-23.0.1:
      Successfully uninstalled pip-23.0.1
Successfully installed pip-24.0 setuptools-69.5.1 wheel-0.43.0
Virtual environment 'r-tensorflow' successfully created.
Using virtual environment 'r-tensorflow' ...
+ /Users/david/.virtualenvs/r-tensorflow/bin/python -m pip install --upgrade --no-user 'tensorflow==2.16.*'
Collecting tensorflow==2.16.*
  Using cached tensorflow-2.16.1-cp310-cp310-macosx_12_0_arm64.whl.metadata (4.1 kB)
Collecting absl-py>=1.0.0 (from tensorflow==2.16.*)
  Using cached absl_py-2.1.0-py3-none-any.whl.metadata (2.3 kB)
Collecting astunparse>=1.6.0 (from tensorflow==2.16.*)
  Using cached astunparse-1.6.3-py2.py3-none-any.whl.metadata (4.4 kB)
Collecting flatbuffers>=23.5.26 (from tensorflow==2.16.*)
  Using cached flatbuffers-24.3.25-py2.py3-none-any.whl.metadata (850 bytes)
Collecting gast!=0.5.0,!=0.5.1,!=0.5.2,>=0.2.1 (from tensorflow==2.16.*)
  Using cached gast-0.5.4-py3-none-any.whl.metadata (1.3 kB)
Collecting google-pasta>=0.1.1 (from tensorflow==2.16.*)
  Using cached google_pasta-0.2.0-py3-none-any.whl.metadata (814 bytes)
Collecting h5py>=3.10.0 (from tensorflow==2.16.*)
  Using cached h5py-3.11.0-cp310-cp310-macosx_11_0_arm64.whl.metadata (2.5 kB)
Collecting libclang>=13.0.0 (from tensorflow==2.16.*)
  Using cached libclang-18.1.1-py2.py3-none-macosx_11_0_arm64.whl.metadata (5.2 kB)
Collecting ml-dtypes~=0.3.1 (from tensorflow==2.16.*)
  Using cached ml_dtypes-0.3.2-cp310-cp310-macosx_10_9_universal2.whl.metadata (20 kB)
Collecting opt-einsum>=2.3.2 (from tensorflow==2.16.*)
  Using cached opt_einsum-3.3.0-py3-none-any.whl.metadata (6.5 kB)
Collecting packaging (from tensorflow==2.16.*)
  Using cached packaging-24.0-py3-none-any.whl.metadata (3.2 kB)
Collecting protobuf!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.20.3 (from tensorflow==2.16.*)
  Using cached protobuf-4.25.3-cp37-abi3-macosx_10_9_universal2.whl.metadata (541 bytes)
Collecting requests<3,>=2.21.0 (from tensorflow==2.16.*)
  Using cached requests-2.31.0-py3-none-any.whl.metadata (4.6 kB)
Requirement already satisfied: setuptools in /Users/david/.virtualenvs/r-tensorflow/lib/python3.10/site-packages (from tensorflow==2.16.*) (69.5.1)
Collecting six>=1.12.0 (from tensorflow==2.16.*)
  Using cached six-1.16.0-py2.py3-none-any.whl.metadata (1.8 kB)
Collecting termcolor>=1.1.0 (from tensorflow==2.16.*)
  Using cached termcolor-2.4.0-py3-none-any.whl.metadata (6.1 kB)
Collecting typing-extensions>=3.6.6 (from tensorflow==2.16.*)
  Using cached typing_extensions-4.11.0-py3-none-any.whl.metadata (3.0 kB)
Collecting wrapt>=1.11.0 (from tensorflow==2.16.*)
  Using cached wrapt-1.16.0-cp310-cp310-macosx_11_0_arm64.whl.metadata (6.6 kB)
Collecting grpcio<2.0,>=1.24.3 (from tensorflow==2.16.*)
  Using cached grpcio-1.62.2-cp310-cp310-macosx_12_0_universal2.whl.metadata (4.0 kB)
Collecting tensorboard<2.17,>=2.16 (from tensorflow==2.16.*)
  Using cached tensorboard-2.16.2-py3-none-any.whl.metadata (1.6 kB)
Collecting keras>=3.0.0 (from tensorflow==2.16.*)
  Using cached keras-3.3.0-py3-none-any.whl.metadata (5.8 kB)
Collecting tensorflow-io-gcs-filesystem>=0.23.1 (from tensorflow==2.16.*)
  Using cached tensorflow_io_gcs_filesystem-0.36.0-cp310-cp310-macosx_12_0_arm64.whl.metadata (14 kB)
Collecting numpy<2.0.0,>=1.23.5 (from tensorflow==2.16.*)
  Using cached numpy-1.26.4-cp310-cp310-macosx_11_0_arm64.whl.metadata (61 kB)
Requirement already satisfied: wheel<1.0,>=0.23.0 in /Users/david/.virtualenvs/r-tensorflow/lib/python3.10/site-packages (from astunparse>=1.6.0->tensorflow==2.16.*) (0.43.0)
Collecting rich (from keras>=3.0.0->tensorflow==2.16.*)
  Using cached rich-13.7.1-py3-none-any.whl.metadata (18 kB)
Collecting namex (from keras>=3.0.0->tensorflow==2.16.*)
  Using cached namex-0.0.8-py3-none-any.whl.metadata (246 bytes)
Collecting optree (from keras>=3.0.0->tensorflow==2.16.*)
  Using cached optree-0.11.0-cp310-cp310-macosx_11_0_arm64.whl.metadata (45 kB)
Collecting charset-normalizer<4,>=2 (from requests<3,>=2.21.0->tensorflow==2.16.*)
  Using cached charset_normalizer-3.3.2-cp310-cp310-macosx_11_0_arm64.whl.metadata (33 kB)
Collecting idna<4,>=2.5 (from requests<3,>=2.21.0->tensorflow==2.16.*)
  Using cached idna-3.7-py3-none-any.whl.metadata (9.9 kB)
Collecting urllib3<3,>=1.21.1 (from requests<3,>=2.21.0->tensorflow==2.16.*)
  Using cached urllib3-2.2.1-py3-none-any.whl.metadata (6.4 kB)
Collecting certifi>=2017.4.17 (from requests<3,>=2.21.0->tensorflow==2.16.*)
  Using cached certifi-2024.2.2-py3-none-any.whl.metadata (2.2 kB)
Collecting markdown>=2.6.8 (from tensorboard<2.17,>=2.16->tensorflow==2.16.*)
  Using cached Markdown-3.6-py3-none-any.whl.metadata (7.0 kB)
Collecting tensorboard-data-server<0.8.0,>=0.7.0 (from tensorboard<2.17,>=2.16->tensorflow==2.16.*)
  Using cached tensorboard_data_server-0.7.2-py3-none-any.whl.metadata (1.1 kB)
Collecting werkzeug>=1.0.1 (from tensorboard<2.17,>=2.16->tensorflow==2.16.*)
  Using cached werkzeug-3.0.2-py3-none-any.whl.metadata (4.1 kB)
Collecting MarkupSafe>=2.1.1 (from werkzeug>=1.0.1->tensorboard<2.17,>=2.16->tensorflow==2.16.*)
  Using cached MarkupSafe-2.1.5-cp310-cp310-macosx_10_9_universal2.whl.metadata (3.0 kB)
Collecting markdown-it-py>=2.2.0 (from rich->keras>=3.0.0->tensorflow==2.16.*)
  Using cached markdown_it_py-3.0.0-py3-none-any.whl.metadata (6.9 kB)
Collecting pygments<3.0.0,>=2.13.0 (from rich->keras>=3.0.0->tensorflow==2.16.*)
  Using cached pygments-2.17.2-py3-none-any.whl.metadata (2.6 kB)
Collecting mdurl~=0.1 (from markdown-it-py>=2.2.0->rich->keras>=3.0.0->tensorflow==2.16.*)
  Using cached mdurl-0.1.2-py3-none-any.whl.metadata (1.6 kB)
Using cached tensorflow-2.16.1-cp310-cp310-macosx_12_0_arm64.whl (227.0 MB)
Using cached absl_py-2.1.0-py3-none-any.whl (133 kB)
Using cached astunparse-1.6.3-py2.py3-none-any.whl (12 kB)
Using cached flatbuffers-24.3.25-py2.py3-none-any.whl (26 kB)
Using cached gast-0.5.4-py3-none-any.whl (19 kB)
Using cached google_pasta-0.2.0-py3-none-any.whl (57 kB)
Using cached grpcio-1.62.2-cp310-cp310-macosx_12_0_universal2.whl (10.0 MB)
Using cached h5py-3.11.0-cp310-cp310-macosx_11_0_arm64.whl (2.9 MB)
Using cached keras-3.3.0-py3-none-any.whl (1.5 MB)
Using cached libclang-18.1.1-py2.py3-none-macosx_11_0_arm64.whl (26.4 MB)
Using cached ml_dtypes-0.3.2-cp310-cp310-macosx_10_9_universal2.whl (389 kB)
Using cached numpy-1.26.4-cp310-cp310-macosx_11_0_arm64.whl (14.0 MB)
Using cached opt_einsum-3.3.0-py3-none-any.whl (65 kB)
Using cached protobuf-4.25.3-cp37-abi3-macosx_10_9_universal2.whl (394 kB)
Using cached requests-2.31.0-py3-none-any.whl (62 kB)
Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Using cached tensorboard-2.16.2-py3-none-any.whl (5.5 MB)
Using cached tensorflow_io_gcs_filesystem-0.36.0-cp310-cp310-macosx_12_0_arm64.whl (3.4 MB)
Using cached termcolor-2.4.0-py3-none-any.whl (7.7 kB)
Using cached typing_extensions-4.11.0-py3-none-any.whl (34 kB)
Using cached wrapt-1.16.0-cp310-cp310-macosx_11_0_arm64.whl (38 kB)
Using cached packaging-24.0-py3-none-any.whl (53 kB)
Using cached certifi-2024.2.2-py3-none-any.whl (163 kB)
Using cached charset_normalizer-3.3.2-cp310-cp310-macosx_11_0_arm64.whl (120 kB)
Using cached idna-3.7-py3-none-any.whl (66 kB)
Using cached Markdown-3.6-py3-none-any.whl (105 kB)
Using cached tensorboard_data_server-0.7.2-py3-none-any.whl (2.4 kB)
Using cached urllib3-2.2.1-py3-none-any.whl (121 kB)
Using cached werkzeug-3.0.2-py3-none-any.whl (226 kB)
Using cached namex-0.0.8-py3-none-any.whl (5.8 kB)
Using cached optree-0.11.0-cp310-cp310-macosx_11_0_arm64.whl (273 kB)
Using cached rich-13.7.1-py3-none-any.whl (240 kB)
Using cached markdown_it_py-3.0.0-py3-none-any.whl (87 kB)
Using cached MarkupSafe-2.1.5-cp310-cp310-macosx_10_9_universal2.whl (18 kB)
Using cached pygments-2.17.2-py3-none-any.whl (1.2 MB)
Using cached mdurl-0.1.2-py3-none-any.whl (10.0 kB)
Installing collected packages: namex, libclang, flatbuffers, wrapt, urllib3, typing-extensions, termcolor, tensorflow-io-gcs-filesystem, tensorboard-data-server, six, pygments, protobuf, packaging, numpy, mdurl, MarkupSafe, markdown, idna, grpcio, gast, charset-normalizer, certifi, absl-py, werkzeug, requests, optree, opt-einsum, ml-dtypes, markdown-it-py, h5py, google-pasta, astunparse, tensorboard, rich, keras, tensorflow
Successfully installed MarkupSafe-2.1.5 absl-py-2.1.0 astunparse-1.6.3 certifi-2024.2.2 charset-normalizer-3.3.2 flatbuffers-24.3.25 gast-0.5.4 google-pasta-0.2.0 grpcio-1.62.2 h5py-3.11.0 idna-3.7 keras-3.3.0 libclang-18.1.1 markdown-3.6 markdown-it-py-3.0.0 mdurl-0.1.2 ml-dtypes-0.3.2 namex-0.0.8 numpy-1.26.4 opt-einsum-3.3.0 optree-0.11.0 packaging-24.0 protobuf-4.25.3 pygments-2.17.2 requests-2.31.0 rich-13.7.1 six-1.16.0 tensorboard-2.16.2 tensorboard-data-server-0.7.2 tensorflow-2.16.1 tensorflow-io-gcs-filesystem-0.36.0 termcolor-2.4.0 typing-extensions-4.11.0 urllib3-2.2.1 werkzeug-3.0.2 wrapt-1.16.0

Installation complete.

There were 18 warnings (use warnings() to see them)
> warnings()
Warning messages:
1: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[1]="/usr/local/bin/python3": No such file or directory
2: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[2]="/usr/local/bin/python3-config": No such file or directory
3: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[3]="/usr/local/bin/python3-intel64": No such file or directory
4: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[4]="/usr/local/bin/python3.10": No such file or directory
5: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[5]="/usr/local/bin/python3.10-config": No such file or directory
6: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[6]="/usr/local/bin/python3.10-intel64": No such file or directory
7: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[1]="/usr/local/bin/python3": No such file or directory
8: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[2]="/usr/local/bin/python3-config": No such file or directory
9: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[3]="/usr/local/bin/python3-intel64": No such file or directory
10: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[4]="/usr/local/bin/python3.10": No such file or directory
11: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[5]="/usr/local/bin/python3.10-config": No such file or directory
12: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[6]="/usr/local/bin/python3.10-intel64": No such file or directory
13: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[1]="/usr/local/bin/python3": No such file or directory
14: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[2]="/usr/local/bin/python3-config": No such file or directory
15: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[3]="/usr/local/bin/python3-intel64": No such file or directory
16: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[4]="/usr/local/bin/python3.10": No such file or directory
17: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[5]="/usr/local/bin/python3.10-config": No such file or directory
18: In normalizePath(Sys.glob(glob), winslash = "/") :
  path[6]="/usr/local/bin/python3.10-intel64": No such file or directory

Some diagnostic info:

> reticulate::py_config()
python:         /Users/david/.virtualenvs/r-tensorflow/bin/python
libpython:      /Users/david/.pyenv/versions/3.10.14/lib/libpython3.10.dylib
pythonhome:     /Users/david/.virtualenvs/r-tensorflow:/Users/david/.virtualenvs/r-tensorflow
version:        3.10.14 (main, Apr 20 2024, 10:21:36) [Clang 14.0.3 (clang-1403.0.22.14.1)]
numpy:          /Users/david/.virtualenvs/r-tensorflow/lib/python3.10/site-packages/numpy
numpy_version:  1.26.4
tensorflow:     /Users/david/.virtualenvs/r-tensorflow/lib/python3.10/site-packages/tensorflow

NOTE: Python version was forced by import("tensorflow")
> tensorflow::tf_config()
TensorFlow v2.16.1 (~/.virtualenvs/r-tensorflow/lib/python3.10/site-packages/tensorflow)
Python v3.10 (~/.virtualenvs/r-tensorflow/bin/python)
> reticulate::import("tensorflow")
Module(tensorflow)
> reticulate::py_last_error()
NULL
> sessionInfo()
R version 4.3.3 (2024-02-29)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Sonoma 14.0

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/Berlin
tzcode source: internal

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

loaded via a namespace (and not attached):
 [1] rappdirs_0.3.3         utf8_1.2.4             generics_0.1.3         lattice_0.22-5         magrittr_2.0.3         grid_4.3.3            
 [7] eppverification_0.4.1  mvtnorm_1.2-4          rprojroot_2.0.4        jsonlite_1.8.8         Matrix_1.6-5           processx_3.8.4        
[13] whisker_0.4.1          ps_1.7.6               tfruns_1.5.3           mgcv_1.9-1             tensorflow_2.16.0.9000 fansi_1.0.6           
[19] scales_1.3.0           permute_0.9-7          cli_3.6.2              rlang_1.1.3            pak_0.7.2              munsell_0.5.1         
[25] splines_4.3.3          base64enc_0.1-3        withr_3.0.0            vegan_2.6-4            tools_4.3.3            parallel_4.3.3        
[31] dplyr_1.1.4            colorspace_2.1-0       ggplot2_3.5.0          here_1.0.1             Rfast_2.1.0            RcppZiggurat_0.1.6    
[37] reticulate_1.36.0.9000 vctrs_0.6.5            R6_2.5.1               png_0.1-8              lifecycle_1.0.4        MASS_7.3-60.0.1       
[43] pcaPP_2.0-4            cluster_2.1.6          pkgconfig_2.0.3        callr_3.7.6            RcppParallel_5.1.7     pillar_1.9.0          
[49] gtable_0.3.4           glue_1.7.0             Rcpp_1.0.12            tibble_3.2.1           tidyselect_1.2.1       rstudioapi_0.16.0     
[55] nlme_3.1-164           compiler_4.3.3    

Unfortunately, calling the code on

https://tensorflow.rstudio.com/examples/conv_lstm

yields to an error as well:

library(keras)
model <- keras_model_sequential()
Error: 

(There is no explicit error message)

Thank you very much in advance!

t-kalinowski commented 2 months ago

Very interesting. Thanks for reporting.

Do you get the same error if you use keras3?

library(keras3)
keras_model_sequential() 

What do the broken /usr/local/bin/python* links point to?

system("ls -l /usr/local/bin/python*")

Can you trackdown where the error is coming from? Something like this might help:

options(error = quote(print(rlang::trace_back())))
<reproduce error>
jobstdavid commented 2 months ago

Thanks, with keras3 it works without any problem! What is the (main) difference between keras3 and keras?

Furthermore, I receive

system("ls -l /usr/local/bin/python*")
lrwxr-xr-x  1 root  admin  70 Nov 24  2021 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3
lrwxr-xr-x  1 root  admin  77 Nov 24  2021 /usr/local/bin/python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3-config
lrwxr-xr-x  1 root  admin  78 Nov 24  2021 /usr/local/bin/python3-intel64 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3-intel64
lrwxr-xr-x  1 root  admin  73 Nov 24  2021 /usr/local/bin/python3.10 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10
lrwxr-xr-x  1 root  admin  80 Nov 24  2021 /usr/local/bin/python3.10-config -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10-config
lrwxr-xr-x  1 root  admin  81 Nov 24  2021 /usr/local/bin/python3.10-intel64 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10-intel64

and

options(error = quote(print(rlang::trace_back())))
model <- keras_model_sequential()
Error: 
▆
t-kalinowski commented 2 months ago

Thanks for reporting, the warning about No such file or directory is fixed in the development version of reticulate now, but that doesn't fix the error you see from keras.

We'll need a traceback to track it down---I can't reproduce the error locally.

Here is another trick for getting a traceback if R is being "shy" like this, wrap the offending call in a function that you're tracing in a debugger, and then repeatedly "step into" (s and Enter, or Shift + F4 in the Rstudio IDE) until you observe the error. At anytime, you can print print(rlang::trace_back()) to see a pretty printout of the current stack trace.


Seeing as how you have some broken symlinks in /usr/local/bin/*, my guess is that there might be other such artifacts related to former python installations on the system, and that might ultimately be the root cause here. Perhaps re-installing python and then recreating the venv might fix the issue in that case.

reticulate::install_python("3.10:latest", force = TRUE) -> python
# TensorFlow version 2.15 is the last version that defaulted to using Keras version 2, 
# which is what the {keras} package is for. TensorFlow 2.16 and later default
# to Keras 3, which you can use from R using the {keras3} package. 
tensorflow::install_tensorflow(version = "2.15", python_version = python)

Also, please double check that PYTHONPATH is not set, nor that any conda hooks are automatically activated in .zshrc or .bashrc or similar.

is_set <- function(x) !is.na(Sys.getenv(x, NA))

if (is_set(c("PYTHONPATH")))
  stop("PYTHONPATH is being set somewhere")

if (any(is_set(c("CONDA_PREFIX", "CONDA_EXE"))))
  stop("Conda is being activated somewhere")
jobstdavid commented 2 months ago

Thanks for the information!

I tried the following in R to trace the error:

profvis::profvis({
keras::keras_model_sequential() 
})

profvis: code exited with error:

Error in parse_rprof_lines(lines, expr_source) : 
No parsing data available. Maybe your function was too fast?
t-kalinowski commented 2 months ago

I don't think profvis will be helpful here. I meant to do something like this

fn <- function() {
  browser()
  keras::keras_model_sequential()
}

fn()
# press the 's' key and then the Enter key
# press the 's' key and then the Enter key
# press the 's' key and then the Enter key
# press the 's' key and then the Enter key 
# ... see where we're going
# evaluate `print(rlang::trace_back())` to see the traceback
jobstdavid commented 2 months ago

Thanks! That's the output:

> fn <- function() {
+   browser()
+   keras::keras_model_sequential()
+ }
> 
> fn()
Called from: fn()
Browse[1]> s
debug at #3: keras::keras_model_sequential()
Browse[2]> s
debugging in: keras::keras_model_sequential()
debug: {
    if (length(list(...))) 
        layers <- c(sequential_model_input_layer(...), layers)
    keras$models$Sequential(layers = layers, name = name)
}
Browse[3]> s
debug: if (length(list(...))) layers <- c(sequential_model_input_layer(...), 
    layers)
Browse[3]> s
debug: keras$models$Sequential(layers = layers, name = name)
Browse[3]> s
debugging in: keras$models$Sequential(layers = layers, name = name)
debug: {
    cl <- sys.call()
    cl[[1L]] <- list2
    call_args <- split_named_unnamed(eval(cl, parent.frame()))
    result <- py_call_impl(callable, call_args$unnamed, call_args$named)
    if (py_get_convert(callable)) 
        result <- py_to_r(result)
    if (is.null(result)) 
        invisible(result)
    else result
}
Browse[4]> s
debug: cl <- sys.call()
Browse[4]> s
debugging in: sys.call()
debug: .Internal(sys.call(which))
Browse[5]> s
exiting from: sys.call()
debug: cl[[1L]] <- list2
Browse[4]> s
debug: call_args <- split_named_unnamed(eval(cl, parent.frame()))
Browse[4]> s
debugging in: split_named_unnamed(eval(cl, parent.frame()))
debug: {
    nms <- names(x)
    if (is.null(nms)) 
        return(list(unnamed = x, named = list()))
    named <- nzchar(nms)
    list(unnamed = x[!named], named = x[named])
}
Browse[5]> s
debug: nms <- names(x)
Browse[5]> s
debugging in: eval(cl, parent.frame())
debug: .Internal(eval(expr, envir, enclos))
Browse[6]> s
debugging in: parent.frame()
debug: .Internal(parent.frame(n))
Browse[7]> s
exiting from: parent.frame()
debug: baseenv()
Browse[6]> s
debugging in: (function (...) 
{
    .Call(ffi_dots_list, frame_env = environment(), named = NULL, 
        ignore_empty = "trailing", preserve_empty = FALSE, unquote_names = TRUE, 
        homonyms = "keep", check_assign = FALSE)
})(layers = layers, name = name)
debug: {
    .Call(ffi_dots_list, frame_env = environment(), named = NULL, 
        ignore_empty = "trailing", preserve_empty = FALSE, unquote_names = TRUE, 
        homonyms = "keep", check_assign = FALSE)
}
Browse[8]> s
debug: .Call(ffi_dots_list, frame_env = environment(), named = NULL, 
    ignore_empty = "trailing", preserve_empty = FALSE, unquote_names = TRUE, 
    homonyms = "keep", check_assign = FALSE)
Browse[8]> s
debugging in: environment()
debug: .Internal(environment(fun))
Browse[9]> s
exiting from: environment()
exiting from: (function (...) 
{
    .Call(ffi_dots_list, frame_env = environment(), named = NULL, 
        ignore_empty = "trailing", preserve_empty = FALSE, unquote_names = TRUE, 
        homonyms = "keep", check_assign = FALSE)
})(layers = layers, name = name)
exiting from: eval(cl, parent.frame())
debug: if (is.null(nms)) return(list(unnamed = x, named = list()))
Browse[5]> s
debug: named <- nzchar(nms)
Browse[5]> s
debug: list(unnamed = x[!named], named = x[named])
Browse[5]> s
exiting from: split_named_unnamed(eval(cl, parent.frame()))
debug: result <- py_call_impl(callable, call_args$unnamed, call_args$named)
Browse[4]> s
debugging in: py_call_impl(callable, call_args$unnamed, call_args$named)
debug: {
    .Call(`_reticulate_py_call_impl`, x, args, keywords)
}
Browse[5]> s
debug: .Call(`_reticulate_py_call_impl`, x, args, keywords)
Browse[5]> s
exiting from: py_call_impl(callable, call_args$unnamed, call_args$named)
debug: if (py_get_convert(callable)) result <- py_to_r(result)
Browse[4]> s
debugging in: py_get_convert(callable)
debug: {
    .Call(`_reticulate_py_get_convert`, x)
}
Browse[5]> s
debug: .Call(`_reticulate_py_get_convert`, x)
Browse[5]> s
exiting from: py_get_convert(callable)
debug: result <- py_to_r(result)
Browse[4]> s
debugging in: py_to_r(result)
debug: {
    if (!is_py_object(x <- py_to_r_cpp(x))) 
        return(x)
    UseMethod("py_to_r")
}
Browse[5]> s
debug: if (!is_py_object(x <- py_to_r_cpp(x))) return(x)
Browse[5]> s
debugging in: is_py_object(x <- py_to_r_cpp(x))
debug: {
    .Call(`_reticulate_is_py_object`, x)
}
Browse[6]> s
debug: .Call(`_reticulate_is_py_object`, x)
Browse[6]> s
debugging in: py_to_r_cpp(x)
debug: {
    .Call(`_reticulate_py_to_r_cpp`, x)
}
Browse[7]> s
debug: .Call(`_reticulate_py_to_r_cpp`, x)
Browse[7]> s
exiting from: py_to_r_cpp(x)
exiting from: is_py_object(x <- py_to_r_cpp(x))
debug: UseMethod("py_to_r")
Browse[5]> s
debugging in: py_to_r.default(result)
debug: {
    py_to_r_cpp(x)
}
Browse[6]> s
debug: py_to_r_cpp(x)
Browse[6]> s
debugging in: py_to_r_cpp(x)
debug: {
    .Call(`_reticulate_py_to_r_cpp`, x)
}
Browse[7]> s
debug: .Call(`_reticulate_py_to_r_cpp`, x)
Browse[7]> s
exiting from: py_to_r_cpp(x)
exiting from: py_to_r.default(result)
exiting from: py_to_r(result)
debug: if (is.null(result)) invisible(result) else result
Browse[4]> s
debug: result
Browse[4]> s
exiting from: keras$models$Sequential(layers = layers, name = name)
exiting from: keras::keras_model_sequential()
Model: "sequential"
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Layer (type)                                                                        ┃ Output Shape                                                    ┃                              Param # ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
└─────────────────────────────────────────────────────────────────────────────────────┴─────────────────────────────────────────────────────────────────┴──────────────────────────────────────┘
 Total params: 0 (0.00 B)
 Trainable params: 0 (0.00 B)
 Non-trainable params: 0 (0.00 B)
t-kalinowski commented 2 months ago

it seems that there is no error when you step through it with a debugger. Am I reading the output correctly?

But the error still occurs outside a debugger?

jobstdavid commented 2 months ago

Yes, you are reading the output correctly. During debugging, the error does not occur, but outside the debugging the error does occur.

t-kalinowski commented 2 months ago

I'm genuinely stumped about what might be causing the issue.

Do you have anything in .Rprofile or .Renviron that might be causing this? Any other packages loaded?

jobstdavid commented 2 months ago

Wow, thank you very much!!! Indeed, there was an exported path in the .Rprofil linking to a conda env, which I deleted and now it works!!! Thank you so much for your great support!