Problems Loading Dev Version

I am hoping to test out the new calculate and simulate functionality. I think I need the dev version of greta, but after trying:

devtools::install_github("greta-dev/greta")

on two different windows machines, I run into the same error when trying to build the package on my local machine. Each time the install fails saying:

Error: package or namespace load failed for ‘greta’:
.onLoad failed in loadNamespace() for ‘greta’, details:
call: NULL
error: Your current architecture is 32bit; however, this version of Python was compiled for 64bit.
Use reticulate::install_miniconda() if you’d like to install a Miniconda Python environment.

As you can see from these config queries:

>tensorflow::tf_config()
TensorFlow v1.14.0 (C:\Users\ajf\MINICO~1\envs\R-TENS~1\lib\site-packages\tensorflow_init_.p)
Python v3.7 (C:/Users/ajf/Miniconda3/envs/r-tensorflow/python.exe)
>reticulate::py_config()
python: C:/Users/ajf/Miniconda3/envs/r-tensorflow/python.exe
libpython: C:/Users/ajf/Miniconda3/envs/r-tensorflow/python37.dll
pythonhome: C:/Users/ajf/Miniconda3/envs/r-tensorflow
version: 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]
Architecture: 64bit
numpy: C:/Users/ajf/Miniconda3/envs/r-tensorflow/Lib/site-packages/numpy
numpy_version: 1.16.5
tensorflow: C:\Users\ajf\MINICO~1\envs\R-TENS~1\lib\site-packages\tensorflow_init_.p
python versions found:
C:/Users/ajf/Miniconda3/envs/r-tensorflow/python.exe
C:/Users/ajf/Miniconda3/python.exe
C:/Python27/python.exe
C:/Users/ajf/Miniconda3/envs/twilio/python.exe

I am 64-bit and additionally, I am running CRAN greta without issue. Let me know if anyone has a potential idea on working around this. Thanks!

Hmm, that’s annoying.

Looks like another issue with reticulate not looking at the version of python it should be. I’d first confirm whether the issue is with reticulate or tensorflow by starting a new, completely clean, session and loading reticulate and seeing if that works. Then doing the same with tensorflow.

I’ve seen similar issues when the R session has been reset but the global environment is not completely clean. E.g. the default RStudio behaviour in reset is to reload everything in the environment, which can mess up reticulate. There’s an option in RStudio to change that behaviour.

Assuming it’s with reticulate or RStudio (greta only accesses python through them, so it is most likely those) I would recommend searching the issues for those GitHub repos for advice and posting there is this isn’t covered.

Unfortunately this is a pain point that greta can’t do much about, and I assume it’s a difficult thing to fix otherwise the fine folks at RStudio would have it all sorted by now.

Thanks for the quick reply. I uninstalled and reinstalled all my python environments to start fresh. And as per your guidance, I narrowed my investigation to the reticulate package. My most fruitful path of investigation led me to install reticulate by downloading the dev version:

devtools::install_github("rstudio/reticulate")

Then, I started to get a more meaningful error message when trying devtools::install_github("greta-dev/greta"):

Error: package or namespace load failed for 'greta':
 .onLoad failed in loadNamespace() for 'greta', details:
  call: check_forbidden_initialization()
  error: package 'greta' attempted to initialize Python in .onLoad(). 
  Packages should not initialize Python themselves; rather, Python 
  should be loaded on-demand as requested by the user of the package. 
Please see vignette("python_dependencies", package = "reticulate") for more details.
Error: loading failed
Execution halted
ERROR: loading failed for 'i386', 'x64'
* removing 'C:/Users/ajf/Documents/R/win-library/3.6/greta'
* restoring previous 'C:/Users/ajf/Documents/R/win-library/3.6/greta'

So I forked greta and removed anything that might call reticulate from the .onLoad() function like check_tf_version("startup") . All changes are made in the package.R file. Now, if I do an install from the forked repository (devtools::install_github("flyaflya/greta")), I do not get the error anymore and the new greta functions are available to me.

I do not have it fully debugged, but it seems the next version of reticulate will balk at the onLoad() stuff. And my guess is that it balks because of the problems I was experiencing. Anyway, check out the vignette at https://github.com/rstudio/reticulate/blob/master/vignettes/python_dependencies.Rmd because I do think greta will need to change its .onLoad() function to conform to this new way.

Thanks for the help, I am up and running and will play with calculate() shortly.

OK great, thanks for looking into that! I should be able to take a look at this next week