Skip to content Skip to sidebar Skip to footer

Use Reticulate To Call Python Script And Send Email

I use Windows Task Scheduler to run an R Script several times a day. The script transforms some new data and adds it to an existing data file. I want to use reticulate to call a P

Solution 1:

This execution problem

This works correctly when I run it line by line from within RStudio. The problem is that it doesn't work when the script runs on schedule

can stem from multiple reasons:

  1. Multiple Pythons

    You have multiple Python versions where smtplib is installed on one version (e.g., Python 2.7 or Python 3.6) and not the other. Check which Python is being used at command line, Rscript -e "print(Sys.which("python"))" and RStudio, Sys.which("python"). Explicitly define which Python.exe to run with reticulate's use_python("/path/to/python").


  1. Multiple Rs

    You have multiple R versions where Rscript uses a different version than RStudio. Check R.home() variable in both: Rscript -e "print(R.home())" and call R.home() in RStudio. Explicitly call the required Rscript in appropriate R version bin folder: /path/to/R #.#/bin/Rscript "/path/to/code.R".


  1. Multiple Reticulates

    You have multiple reticulate packages installed on same R version, residing in different library locations, each calling a different Python version. Check with the matrix: installed.package(), locating the reticulate row. Explicitly call library(reticulate, lib.loc="/path/to/specific/library").

Post a Comment for "Use Reticulate To Call Python Script And Send Email"