reticulate (version 1.20)

use_python: Use Python

Description

Select the version of Python to be used by reticulate.

Usage

use_python(python, required = FALSE)

use_python_version(version, required = FALSE)

use_virtualenv(virtualenv = NULL, required = FALSE)

use_condaenv(condaenv = NULL, conda = "auto", required = FALSE)

use_miniconda(condaenv = NULL, required = FALSE)

Arguments

python

The path to a Python binary.

required

Is the requested copy of Python required? If TRUE, an error will be emitted if the requested copy of Python does not exist. Otherwise, the request is taken as a hint only, and scanning for other versions will still proceed.

version

The version of Python to use. reticulate will search for versions of Python as installed by the install_python() helper function.

virtualenv

Either the name of, or the path to, a Python virtual environment.

condaenv

The name of the Conda environment to use.

conda

The path to a conda executable. By default, reticulate will check the PATH, as well as other standard locations for Anaconda installations.

RETICULATE_PYTHON

The RETICULATE_PYTHON environment variable can also be used to control which copy of Python reticulate chooses to bind to. It should be set to the path to a Python interpreter, and that interpreter can either be:

  • A standalone system interpreter,

  • Part of a virtual environment,

  • Part of a Conda environment.

When set, this will override any other requests to use a particular copy of Python. Setting this in ~/.Renviron (or optionally, a project .Renviron) can be a useful way of forcing reticulate to use a particular version of Python.

Caveats

By default, requests are advisory, and may be ignored for a number of reasons:

  • The requested copy of Python cannot be initialized,

  • The requested copy of Python does not have an installation of numpy available,

  • Another call to use_python() has requested a different version of Python,

  • The request has been overridden via use_python(..., required = TRUE).

In general, if you explicitly want to use a particular version of Python, it is recommended to set required = TRUE, or explicitly set the RETICULATE_PYTHON environment variable.

Note that the requests for a particular version of Python via use_python() and friends only persist for the active session; they must be re-run in each new R session as appropriate.

Details

The reticulate package initializes its Python bindings lazily -- that is, it does not initialize its Python bindings until an API that explicitly requires Python to be loaded is called. This allows users and package authors to request particular versions of Python by calling use_python() or one of the other helper functions documented in this help file.