@@ -410,6 +410,31 @@ install_tensorflow_virtualenv <- function(python, virtualenv, version, gpu, envn
410
410
stop(" Error " , result , " occurred creating virtualenv at " , virtualenv_path ,
411
411
call. = FALSE )
412
412
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
+
413
438
# function to call pip within virtual env
414
439
pip_install <- function (pkgs , message ) {
415
440
cmd <- sprintf(" %ssource %s && %s install --ignore-installed --upgrade %s%s" ,
@@ -424,14 +449,12 @@ install_tensorflow_virtualenv <- function(python, virtualenv, version, gpu, envn
424
449
stop(" Error " , result , " occurred installing TensorFlow" , call. = FALSE )
425
450
}
426
451
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
+ }
435
458
436
459
# install tensorflow and related dependencies
437
460
pkgs <- tf_pkgs(version , gpu , packages , scipy = TRUE , extra_packages = extra_packages )
0 commit comments