Skip to content

Commit

Permalink
install_python(): discover brew from IDE
Browse files Browse the repository at this point in the history
On macOS, in the RStudio IDE, brew might not be on the PATH, even if it's avilable on the system.
This patch causes reticulate to look for brew in the default homebrew install location, and temporarily add it to the PATH for pyenv to find.
  • Loading branch information
t-kalinowski committed Aug 16, 2023
1 parent 99cec8f commit f66ac0b
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions R/pyenv.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ pyenv_install <- function(version, force, pyenv = NULL) {
# set options
withr::local_envvar(PYTHON_CONFIGURE_OPTS = "--enable-shared")

if(is_macos() &&
Sys.which("brew") == "" &&
file.exists("/opt/homebrew/bin/brew"))
withr::local_path("/opt/homebrew/bin")

# build install arguments
force <- if (force)
"--force"
Expand Down Expand Up @@ -221,9 +226,15 @@ pyenv_bootstrap_unix <- function() {
# pyenv python builds are substantially faster on macOS if we pre-install
# some dependencies (especially openssl) as pre-built but "untapped kegs"
# (i.e., unlinked to somewhere on the PATH but tucked away under $BREW_ROOT/Cellar).
if (nzchar(Sys.which("brew"))) {
system2t("brew", c("install -q openssl readline sqlite3 xz zlib tcl-tk"))
system2t("brew", c("install --only-dependencies pyenv python"))
if (is_macos()) {
brew <- Sys.which("brew")
if(brew == "" && file.exists(brew <- "/opt/homebrew/bin/brew"))
withr::local_path("/opt/homebrew/bin")

if(file.exists(brew)) {
system2t(brew, c("install -q openssl readline sqlite3 xz zlib tcl-tk"))
system2t(brew, c("install --only-dependencies pyenv python"))
}
}

# download the installer
Expand Down

0 comments on commit f66ac0b

Please sign in to comment.