mkearney / googler

googler: Google from the R Console
Other
14 stars 2 forks source link

python is detected but googler() sees otherwise #1

Closed leungi closed 5 years ago

leungi commented 5 years ago

Reprex below.

Sys.setenv("RETICULATE_PYTHON" = "C:\\Users\\leungi\\AppData\\Local\\Continuum\\anaconda3\\python.exe")
reticulate::py_config()
#> python:         C:\Users\leungi\AppData\Local\Continuum\anaconda3\python.exe
#> libpython:      C:/Users/leungi/AppData/Local/Continuum/anaconda3/python37.dll
#> pythonhome:     C:\Users\leungi\AppData\Local\CONTIN~1\ANACON~1
#> version:        3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)]
#> Architecture:   64bit
#> numpy:          C:\Users\leungi\AppData\Local\CONTIN~1\ANACON~1\lib\site-packages\numpy
#> numpy_version:  1.16.4
#> 
#> NOTE: Python version was forced by RETICULATE_PYTHON

library(googler)
googler("rstats")
#> Warning in file.remove("NUL"): cannot remove file 'NUL', reason 'Permission
#> denied'
#> Error in windows_python(): object 'path' not found

# inspecting issue
googler:::windows_python()
#> Warning in file.remove("NUL"): cannot remove file 'NUL', reason 'Permission
#> denied'
#> Error in googler:::windows_python(): object 'path' not found

# checking windows_python()
windows_python <- function(x) {
  if (!grepl("python", googler:::sys_which("python"))) {
    stop("'googler' requires python, which does not appear to be installed.")
  }
  path
}

# checking sys_which()
x <- "python"

if (googler:::is_unix()) {
  return(Sys.which(x))
}
sys_win <- function(x) {
  suppressWarnings({
    path <- tryCatch(
      system(sprintf("where %s", x), intern = TRUE)[1],
      error = function(e) NA_character_
    )
  })
  if (file.exists("NUL")) {
    file.remove("NUL")
  }
  if (!is.na(path)) {
    return(`names<-`(path, x))
  }
  Sys.which(x)
}
vapply(x, sys_win, character(1))
#> Warning in file.remove("NUL"): cannot remove file 'NUL', reason 'Permission
#> denied'
#>                                                                python 
#> "C:\\Users\\leungi\\AppData\\Local\\Continuum\\anaconda3\\python.exe"

## python is detected, but yet path from sys_which() is NULL

path
#> Error in eval(expr, envir, enclos): object 'path' not found

Created on 2019-08-31 by the reprex package (v0.2.1)

mkearney commented 5 years ago

It should be in a lot better shape now, but your path to anaconda3\\python.exe makes me think I need to look for the number 3 both after and before python in python executable. Would love to have my windows machine working for easier testing...

leungi commented 5 years ago

Fixed this issue; raised another (will post separately).