4

I'm trying to use reticulate in R to access Python's win32com (in order to read password-protected Excel documents), but am failing at the first hurdle. Although my code works fine in Python, when trying to use it in reticulate, the win32com module cannot be found.

As an example:

library(reticulate)
virtualenv_create("r-reticulate-test")
py_install(envname = "r-reticulate-test", packages = "pywin32")
win32 = import("win32com.client")

Results in:

Error in py_module_import(module, convert = convert) : 
    ModuleNotFoundError: No module named 'win32com'
Matt
  • 518
  • 2
  • 5
  • 19

1 Answers1

2

I had the same problem and the following solved the issue:

library(reticulate)
install.packages("Rcpp")
virtualenv_create("r-reticulate-test")
py_install("pypiwin32", pip = T, envname = "r-reticulate-test")
win32 <- import("win32com.client")
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Adriana Huante
  • 352
  • 2
  • 11
  • For explanation, `win32com` is only available for Python on Windows environments (not Mac/Linux or other OSes). Hence, your solution to run a Python Windows vritualenv is required. – Parfait Dec 21 '21 at 15:27