Skip to content

Commit 87af538

Browse files
committed
only update pip if it's < v8.1
1 parent d2f1d5c commit 87af538

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

R/install.R

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,31 @@ install_tensorflow_virtualenv <- function(python, virtualenv, version, gpu, envn
410410
stop("Error ", result, " occurred creating virtualenv at ", virtualenv_path,
411411
call. = FALSE)
412412

413+
414+
# see what version of pip is installed (assume 0.1 on error)
415+
installed_pip_version <- function() {
416+
tryCatch({
417+
# check existing version
418+
cmd <- sprintf("%ssource %s && %s --version%s",
419+
ifelse(is_osx(), "", "/bin/bash -c \""),
420+
shQuote(path.expand(virtualenv_bin("activate"))),
421+
shQuote(path.expand(virtualenv_bin(pip_version))),
422+
ifelse(is_osx(), "", "\""))
423+
result <- system(cmd, intern = TRUE, ignore.stderr = TRUE)
424+
425+
# parse result
426+
matches <- regexec("^[^ ]+\\s+(\\d+)\\.(\\d+).*$", result)
427+
matches <- regmatches(result, matches)[[1]]
428+
429+
# return as R numeric version
430+
numeric_version(paste(matches[[2]], matches[[3]], sep = "."))
431+
432+
}, error = function(e) {
433+
warning("Error occurred checking pip version: ", e$message)
434+
numeric_version("0.1")
435+
})
436+
}
437+
413438
# function to call pip within virtual env
414439
pip_install <- function(pkgs, message) {
415440
cmd <- sprintf("%ssource %s && %s install --ignore-installed --upgrade %s%s",
@@ -424,14 +449,12 @@ install_tensorflow_virtualenv <- function(python, virtualenv, version, gpu, envn
424449
stop("Error ", result, " occurred installing TensorFlow", call. = FALSE)
425450
}
426451

427-
# upgrade pip so it can find tensorflow
428-
pip_install("pip", "Upgrading pip")
429-
430-
# install updated version of the wheel package
431-
pip_install("wheel", "Upgrading wheel")
432-
433-
# upgrade setuptools so it can use wheels
434-
pip_install("setuptools", "Upgrading setuptools")
452+
# upgrade pip and related utilities if its older than 8.1
453+
if (installed_pip_version() < "8.1") {
454+
pip_install("pip", "Upgrading pip")
455+
pip_install("wheel", "Upgrading wheel")
456+
pip_install("setuptools", "Upgrading setuptools")
457+
}
435458

436459
# install tensorflow and related dependencies
437460
pkgs <- tf_pkgs(version, gpu, packages, scipy = TRUE, extra_packages = extra_packages)

0 commit comments

Comments
 (0)