Skip to content
This repository has been archived by the owner on Jun 25, 2022. It is now read-only.

Switching between python virtualevs (e.g. support greta / multiple tensorflow versions) #29

Open
cboettig opened this issue Apr 6, 2020 · 1 comment

Comments

@cboettig
Copy link
Member

cboettig commented Apr 6, 2020

We had set the env var RETICULATE_PYTHON_ENV in the global environmental variable so that any user will have access to a system-wide python virtual environment.

Sometimes users will want a separate virtual environment, e.g. to use packages that require older / specific versions of tensorflow, such as greta (v0.3.1).

## set up required greta (0.3.1) env
library(reticulate)
virtualenv_install(envname="/opt/venv/greta", 
  packages = c("tensorflow==1.14.0", 
                         "tensorflow_probability==0.7.0") )

use_virtualenv("/opt/venv/greta")

## test this is 1.14.0 and not 2.0:
tensorflow::tf_version()

Unfortunately, this doesn't change the virtualenv, because it's been locked by the env var, requiring the user to override that setting, e..g by using a local .Renviron that sets RETICULATE_PYTHON_ENV=/opt/venv/greta.

A better solution is for us to set WORKON_HOME env var (e.g. to /opt/venv). This allows reticulate() to "discover" the default reticulate virtualenv we create in /opt/venv/reticulate, so we have an out-of-the-box environment, while the above commands can be run from a fresh R session to set up a new environment without having to restart the R session and mess with Renviron.

Note: when we don't force RETICULATE_PYTHON_ENV, reticulate;:py_config() harasses us to install miniconda instead of using the system Python:

reticulate::py_config()
No non-system installation of Python could be found.
Would you like to download and install Miniconda?

What does reticulate have against the system-installation of python? I get that reticulate() emphasizes user-level $HOME installs of everything over system-wide defaults, but this message seems a little too pushy given that it's already detected a perfectly viable system installation...

@cboettig
Copy link
Member Author

cboettig commented Apr 6, 2020

p.s. note that we still have to restart our R session to switch between virtualenvs, I'm not sure why that's the case. It seems the first call to py_config() or tf_version() etc loads and locks us in to that version for the remainder of the session, even though a subsequent call to use_virtualenv() doesn't throw any message/error.

cboettig added a commit to rocker-org/rocker-versioned2 that referenced this issue Apr 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant