Search code examples
pythonrrstudioarcgisreticulate

R reticulate specifying python executable to use


First, I'm working on a Windows machine. I would like to specify a specific version of python to use in RStudio. I would like RStudio to use python 3 in the ArcGIS Pro folder in order to have arcpy available, along with the licensed extensions. I have reticulate installed and have tried the following methods to force RStudio to use the ArcGIS Pro version of python.

First I tried this:

library(reticulate)
use_python("C:/Program Files/ArcGIS/Pro/bin/Python/envs/arcgispro-py3/python.exe", required = TRUE)

The resulting error:

Error in path.expand(path) : invalid 'path' argument

Following some other tips, I tried setting the environment before loading the reticulate library.

Sys.setenv(RETICULATE_PYTHON = "c:/Program Files/ArcGIS/Pro/bin/Python/envs/arcgispro-py3/python.exe")
library(reticulate)

Then I retrieve information about the the version of Python currently being used by reticulate.

py_config
Error in path.expand(path) : invalid 'path' argument

I also tried creating and editing the .Renviron by using the usethis package

usethis::edit_r_environ()

Then entering the following

RETICULATE_PYTHON="C:/Program Files/ArcGIS/Pro/bin/Python/envs/arcgispro-py3/python.exe"

And saving it, restarting R..

library (reticulate)
py_config()
Error in path.expand(path) : invalid 'path' argument

And, to confirm, here is the location... enter image description here

Any ideas on why I continue to receive invalid 'path' argument

UPDATE (1/11/24): This doesn't seem to be an issue with the reticulate package anymore. My current configuration is R version: 4.3.2, reticulate version: 1.34.0, RStudio version: 2023.12.0, ArcGIS Pro version: 3.2.0.


Solution

  • I was having a similar issue. After trying a whole assortment of things, I finally installed an archived version of reticulate (reticulate_1.22) instead of using the most up-to-date version (reticulate_1.23) and now the issue is gone. It appears that this bug has been brought to the developers' attention (https://github.com/rstudio/reticulate/issues/1189).