Learn R Programming

renv (version 0.9.3)

use_python: Use Python

Description

Associate a version of Python with your project.

Usage

use_python(
  python = NULL,
  ...,
  type = c("auto", "virtualenv", "conda", "system"),
  name = NULL,
  project = NULL
)

Arguments

python

The path to a Python binary. This can be the path to a Python binary on the system, or the path to a Python binary within an already-existing Python environment. If NULL, the RETICULATE_PYTHON environment variable is checked; if that is not set, then the default version of python on the PATH is used instead. As a special case, use_python(FALSE) can be used to deactivate Python integration with a project.

...

Optional arguments; currently unused.

type

The type of Python environment to use. When "auto" (the default), a project-local environment (virtual environments on Linux / macOS; conda environments on Windows) will be created. Ignored if the requested version of python lives within a pre-existing Python environment.

name

The name or path that should be used for the associated Python environment. If NULL and python points to a Python executable living within a pre-existing virtual environment, that environment will be used. Otherwise, a project-local environment will be created instead.

project

The project directory. If NULL, then the active project will be used. If no project is currently active, then the current working directory is used instead.

Value

TRUE, indicating that the requested version of Python has been successfully activated. Note that this function is normally called for its side effects.

Details

When Python integration is active, renv will:

  • Save metadata about the requested version of Python in renv.lock -- in particular, the Python version, and the Python type ("virtualenv", "conda", "system"),

  • On load, set the RETICULATE_PYTHON environment variable, so that the reticulate package can automatically use the requested copy of Python as appropriate,

  • Capture the set of installed Python packages during renv::snapshot(),

  • Reinstall the set of recorded Python packages during renv::restore().

Examples

Run this code
# NOT RUN {
# use python with a project
renv::use_python()

# use virtualenv python with a project
renv::use_python(type = "virtualenv")

# use conda python with a project
renv::use_python(type = "conda")

# }

Run the code above in your browser using DataLab