3

Environment: Windows 7, ArcGIS Pro 2.1, R 3.5.1 with reticulate v1.10.

ArcGIS Pro comes with a pre-configured python 3 conda environment that I'm trying to access in R. Related questions here and at stackoverflow all seem to focus on a similar situation with ArcMap 10.x, but that uses python 2.7 and doesn't use conda, so they haven't been much help.

If I'm reading the reticulate documentation correctly, the following should work:

library(reticulate)

arcpy3_dir <- 'C:/Program Files/ArcGIS/Pro/bin/Python'

use_condaenv(condaenv = file.path(arcpy3_dir, 'envs', 'arcgispro-py3'),
             conda    = file.path(arcpy3_dir, 'Scripts' ,'conda.exe'), 
             required = TRUE)

However, I'm getting an 'unable to locate conda environment' error.

There are some .bat files in the same directory as conda.exe that seem to do a lot of temporary messing about with system paths (more commentary here for an older version of ArcGIS Pro), but I don't know enough about shell scripts to clearly understand what they're doing. I think I need to set some environment variables with Sys.setenv(), but I'm not sure which. I tried

Sys.setenv('CONDA_NEW_ENV' = 'C:/Program Files/ArcGIS/Pro/bin/Python/envs/arcgispro-py3',
           'CONDA_EXE'     = file.path(arcpy3_dir, 'Scripts' ,'conda.exe'),
           'CONDA_SCRIPTS' = file.path(arcpy3_dir, 'Scripts'))

but that doesn't appear to be sufficient.

Has anyone managed to successfully access the ArcGIS Pro conda environment in R, using reticulate?

1
  • You have the correct environment but you have to call Conda activate Commented Nov 13, 2018 at 5:40

1 Answer 1

2

I finally cracked this (I am now using Win10, ArcGIS Pro 2.2.4 and R 3.6.1, but that shouldn't matter):

library(reticulate)
arcpy3_dir <- 'C:/Program Files/ArcGIS/Pro/bin/Python'
system2(file.path(arcpy3_dir, 'Scripts', 'proenv.bat'))

Then you can

import('arcpy')

and proceed, or use {python} chunks in an R markdown document e.g.

```{python}
import arcpy
/* etc */
```

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.