Repository navigation
Closed
Description
By default, RStudio tries to place the configured copy of python on the PATH.
However, there are a couple of issues.
-
The preference is called "automatically activate project-local Python environments", but it seems like we're trying to activate non-local Python installations as well.
-
If we're trying to activate a "system" copy of Python, we end up putting that directory on the PATH as well. This implies that if
pythonis installed at/usr/bin/python, then we'll end up prepending/usr/binto the PATH, which is undesired.
For reference, the code handling this logic lives here:
rstudio/src/cpp/session/modules/SessionPythonEnvironments.R
Lines 242 to 299 in 50250e0
| .rs.addFunction("python.initialize", function(projectDir) | |
| { | |
| # do nothing if the user hasn't opted in | |
| activate <- .rs.readUiPref("python_project_environment_automatic_activate") | |
| if (!identical(activate, TRUE)) | |
| return() | |
| # find path to python interpreter for this project | |
| pythonPath <- .rs.python.configuredInterpreterPath(projectDir) | |
| if (!file.exists(pythonPath)) | |
| return() | |
| # normalize path (avoid following symlinks) | |
| pythonPath <- file.path( | |
| normalizePath(dirname(pythonPath), winslash = "/", mustWork = FALSE), | |
| basename(pythonPath) | |
| ) | |
| # add the Python directory to the PATH | |
| pythonBin <- dirname(pythonPath) | |
| .rs.prependToPath(pythonBin) | |
| # if we have a Scripts directory, place that on the PATH as well | |
| # (primarily for Windows + conda environments) | |
| scriptsPath <- file.path(pythonBin, "Scripts") | |
| if (file.exists(scriptsPath)) | |
| .rs.prependToPath(scriptsPath) | |
| pythonInfo <- .rs.python.getPythonInfo(pythonPath, strict = TRUE) | |
| # if this is a virtual environment, set VIRTUAL_ENV | |
| if (identical(pythonInfo$type, "virtualenv")) | |
| { | |
| envPath <- dirname(dirname(pythonPath)) | |
| Sys.setenv(VIRTUAL_ENV = envPath) | |
| } | |
| # if this is a conda environment, set CONDA_PREFIX | |
| if (identical(pythonInfo$type, "conda")) | |
| { | |
| condaPrefix <- pythonBin | |
| if (!.rs.platform.isWindows) | |
| condaPrefix <- dirname(condaPrefix) | |
| Sys.setenv(CONDA_PREFIX = condaPrefix) | |
| # also ensure that conda is placed on the PATH | |
| condaPath <- .rs.python.findCondaForEnvironment(condaPrefix) | |
| if (file.exists(condaPath)) | |
| .rs.prependToPath(dirname(condaPath)) | |
| } | |
| # also set RETICULATE_PYTHON_FALLBACK so this python is used by default | |
| Sys.setenv(RETICULATE_PYTHON_FALLBACK = pythonPath) | |
| # return path to python | |
| invisible(pythonPath) | |
| }) |
See also; Pro ticket 84885; Pro ticket 85583

Activity
mikebessuille commentedon Mar 6, 2023
Possibly related to #10997 ?
aronatkins commentedon Jul 6, 2023
This PATH adjustment causes problems on systems that need to locate tools installed into
/usr/local/bin(e.g. a homebrew-installed version oftidy). With this option selected, the macOS installed/usr/bin/tidyis always used. This old version of tidy incorrectly reports a number of issues when runningdevtools::check(remote = TRUE, manual = TRUE)against R packages.DavisVaughan commentedon Jul 31, 2023
I just had exactly the same issue as @aronatkins with my new Mac
i.e.
Where
Restarting R session...also included me turning offAutomatically activate project-local Python environmentskevinushey commentedon Feb 6, 2025
I think this was resolved in #13497.