init_py_env: Recipe for installation using 'py_require'

View source: R/init_py_env.R

init_py_envR Documentation

Recipe for installation using py_require

Description

Initialize the required Python environment with the required modules, using procedures introduced in reticulate 1.42.0.

Usage

init_py_env(
    cuda=FALSE, test_cuda=cuda, test_dynamo=TRUE, force=FALSE,
    test_torch=test_cuda || test_dynamo,
    verbose=interactive())

Arguments

cuda

Boolean: Whether to install cuda device (only needed once).

test_cuda

Boolean: whether to test that cuda device can be used.

test_dynamo

Boolean: whether to test that "torch._dynamo" module can be imported. In particular, this test whether libstdc++ is accessible where this module expects it. See Details if the test fails

test_torch

Boolean: whether to test that "torch" module can be imported.

force

Boolean: Whether to force re-installation of miniconda.

verbose

Boolean: Whether to reprot progress of the different steps of the procedure.

Details

The the attempt to import the "torch._dynamo" module may fail on linux with message ImportError: cannot import name 'NP_SUPPORTED_MODULES' from 'torch._dynamo.utils'. If so, seek the libstdc++ library in the r-reticulate architecture (something like /home/<MY_USER_NAME>/.local/share/r-miniconda/lib/libstdc++.so.6.0.29), and either create a symbolic link to it as libstdc++.so.6 in (likely path) /usr/lib/x86_64-linux-gnu/, or change the PATH variable: export LD_LIBRARY_PATH=/home/<MY_USER_NAME>/.local/share/r-miniconda/lib/:$LD_LIBRARY_PATH. On the WSL, I found that the symbolic link is overwritten each time the WSL is restarted.

Value

Returns NULL invisibly.

See Also

get_py_MAF_handle

Examples

# See help("get_py_MAF_handle") for basic usage

# The following test may be useful in broader contexts:
## Not run:  # too slow for CRAN checks
if ( ! reticulate::py_available(initialize = FALSE)) init_py_env(test_cuda=FALSE)

## End(Not run)

mafR documentation built on May 7, 2026, 5:09 p.m.

Related to init_py_env in mafR...