Debian Codegraph @

man/use_python.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/use-python.R
3 \name{use_python}
4 \alias{use_python}
5 \title{Use python}
6 \usage{
7 use_python(
8 python = NULL,
9 ...,
10 type = c("auto", "virtualenv", "conda", "system"),
11 name = NULL,
12 project = NULL
13 )
14 }
15 \arguments{
16 \item{python}{The path to the version of Python to be used with this project. See
17 \strong{Finding Python} for more details. Alternatively, set \code{python = FALSE}
18 to deactivate Python integration for the project -- this removes the
19 \code{Python} section from \code{renv.lock}.}
20
21 \item{...}{Optional arguments; currently unused.}
22
23 \item{type}{The type of Python environment to use. When \code{"auto"} (the default),
24 virtual environments will be used.}
25
26 \item{name}{The name or path that should be used for the associated Python environment.
27 If \code{NULL} and \code{python} points to a Python executable living within a
28 pre-existing virtual environment, that environment will be used. Otherwise,
29 a project-local environment will be created instead, using a name
30 generated from the associated version of Python.}
31
32 \item{project}{The project directory. If \code{NULL}, then the active project will
33 be used. If no project is currently active, then the current working
34 directory is used instead.}
35 }
36 \value{
37 \code{TRUE}, indicating that the requested version of Python has been
38 successfully activated. Note that this function is normally called for its
39 side effects.
40 }
41 \description{
42 Associate a version of Python with your project.
43 }
44 \details{
45 When Python integration is active, renv will:
46 \itemize{
47 \item Save metadata about the requested version of Python in \code{renv.lock} -- in
48 particular, the Python version, and the Python type ("virtualenv", "conda",
49 "system"),
50 \item Capture the set of installed Python packages during \code{renv::snapshot()},
51 \item Re-install the set of recorded Python packages during \code{renv::restore()}.
52 }
53
54 In addition, when the project is loaded, the following actions will be taken:
55 \itemize{
56 \item The \code{RENV_PYTHON} environment variable will be set, indicating the version
57 of Python currently active for this sessions,
58 \item The \code{RETICULATE_PYTHON} environment variable will be set, so that the
59 reticulate package can automatically use the requested copy of Python
60 as appropriate,
61 \item The requested version of Python will be placed on the \code{PATH}, so that
62 attempts to invoke Python will resolve to the expected version of Python.
63 }
64
65 You can override the version of Python used in a particular project by
66 setting the \code{RENV_PYTHON} environment variable; e.g. as part of the
67 project's \code{.Renviron} file. This can be useful if you find that renv
68 is unable to automatically discover a compatible version of Python to
69 be used in the project.
70 }
71 \section{Finding Python}{
72 In interactive sessions, when \code{python = NULL}, renv will prompt for an
73 appropriate version of Python. renv will search a pre-defined set of
74 locations when attempting to find Python installations on the system:
75 \itemize{
76 \item \code{getOption("renv.python.root")},
77 \item \verb{/opt/python},
78 \item \verb{/opt/local/python},
79 \item \verb{~/opt/python},
80 \item \verb{/usr/local/opt} (for macOS Homebrew-installed copies of Python),
81 \item \verb{/opt/homebrew/opt} (for M1 macOS Homebrew-installed copies of Python),
82 \item \verb{~/.pyenv/versions},
83 \item Python instances available on the \code{PATH}.
84 }
85
86 In non-interactive sessions, renv will first check the \code{RETICULATE_PYTHON}
87 environment variable; if that is unset, renv will look for Python on the
88 \code{PATH}. It is recommended that the version of Python to be used is explicitly
89 supplied for non-interactive usages of \code{use_python()}.
90 }
91
92 \section{Warning}{
93 We strongly recommend using Python virtual environments, for a few reasons:
94 \enumerate{
95 \item If something goes wrong with a local virtual environment, you can safely
96 delete that virtual environment, and then re-initialize it later, without
97 worry that doing so might impact other software on your system.
98 \item If you choose to use a "system" installation of Python, then any packages
99 you install or upgrade will be visible to any other application that
100 wants to use that same Python installation. Using a virtual environment
101 ensures that any changes made are isolated to that environment only.
102 \item Choosing to use Anaconda will likely invite extra frustration in the
103 future, as you may be required to upgrade and manage your Anaconda
104 installation as new versions of Anaconda are released. In addition,
105 Anaconda installations tend to work poorly with software not specifically
106 installed as part of that same Anaconda installation.
107 }
108
109 In other words, we recommend selecting "system" or "conda" only if you are an
110 expert Python user who is already accustomed to managing Python / Anaconda
111 installations on your own.
112 }
113
114 \examples{
115 \dontrun{
116
117 # use python with a project
118 renv::use_python()
119
120 # use python with a project; create the environment
121 # within the project directory in the '.venv' folder
122 renv::use_python(name = ".venv")
123
124 # use python with a pre-existing virtual environment located elsewhere
125 renv::use_python(name = "~/.virtualenvs/env")
126
127 # use virtualenv python with a project
128 renv::use_python(type = "virtualenv")
129
130 # use conda python with a project
131 renv::use_python(type = "conda")
132
133 # deactivate Python integration
134 renv::use_python(python = FALSE)
135
136 }
137 }