View source: R/python_backend.R
| greta_set_python | R Documentation |
greta runs on Python (via TensorFlow and TensorFlow Probability). By default
it uses uv (via the reticulate R package) to
install a compatible Python, TensorFlow, and TensorFlow Probability
automatically on first use. greta_set_python() persistently selects which
Python environment greta uses: the managed (uv) environment, a conda
environment (for example one created by install_greta_deps()), or your
own Python. greta_reset_python() clears the stored choice, returning to
greta's automatic resolution.
To choose which versions of TensorFlow and TensorFlow Probability the
managed (uv) environment installs, see greta_set_deps() - dependency
versions are separate from the choice of Python environment.
greta_set_python(backend = c("uv", "conda", "path"), path = NULL, name = NULL)
greta_reset_python()
backend |
Which Python environment to use. One of:
|
path |
Only for |
name |
Only for |
greta resolves which Python to use, in this order:
The RETICULATE_PYTHON environment variable, if set (usually in
~/.Renviron, your .Rprofile, or your shell environment). This
always wins: it takes precedence over any stored preference.
Your stored preference, set with greta_set_python().
An auto-detected "greta-env-tf2" conda environment (created by
install_greta_deps()) - kept so setups from older greta versions keep
working after upgrading.
Otherwise, the managed (uv) environment (the default as of greta 0.6.0): reticulate installs a compatible Python, TensorFlow, and TensorFlow Probability automatically on first use. No setup is needed - this happens "automagically".
For the managed (uv) environment, greta automatically enables uv's offline
mode once the environment is installed, so it no longer reaches out to
PyPI. Set UV_OFFLINE=0 yourself to force online resolution (for example,
to refresh the environment), or UV_OFFLINE=1 to force offline mode -
greta never overrides a value you have already set.
To check which Python greta is currently using, and which it will use
after a restart, call greta_sitrep().
If a stored preference appears to be ignored, RETICULATE_PYTHON is
usually why: remove it from wherever it is set (for example
~/.Renviron), then restart R. Note that Sys.unsetenv() within a
session is not enough, as the choice is applied when greta loads.
Your choice is stored under tools::R_user_dir("greta", "config") and
applied the next time greta is loaded, so you will need to restart R
for it to take effect.
Invisibly, the stored preference (NULL for greta_reset_python()).
greta_set_deps(), greta_sitrep(), install_greta_deps(),
greta_remove()
## Not run:
# use the managed (uv) environment (the default)
greta_set_python()
# use the conda environment from install_greta_deps()
greta_set_python("conda")
# use a differently-named conda environment
greta_set_python("conda", name = "my-tf-env")
# use a specific Python binary, or an environment directory
greta_set_python("path", path = "/path/to/python")
greta_set_python("path", path = "/opt/python-envs/greta")
# clear the stored choice and return to automatic resolution
greta_reset_python()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.