Using `arcgisbinding` and `reticulate` to run R code and python within a Quarto document

67 Views Asked by At

Background

I am a long-time R user but completely new to python. I have used the arcgisbinding package successfully for several years and I am happy with how it is working - I am connecting to my AGOL account there and exporting file geodatabases (fGDB) without issue.

Recently I found a script online to help me truncate and append to an AGOL feature service, written in python. I need to pull data from a web service using an API written for R, convert it to a fGDB, and use the python script to "overwrite" the data currently sitting in AGOL.

I tried out my scripts using test data that I had already created in another R script and everything worked. Then, I tried to put everything together in one script: pull the data from the webservice using an API, export to fGDB with arcgisbinding, and overwrite the older data in AGOL with the python code in one Quarto document.

The issue

However, it seems like arcgisbinding and reticulate are using different versions of python.

Please note: I know nothing about how to create an environment and have no experience with command line coding! So if you know what the issue is here, please be as detailed as possible in how to remedy it.

Example code and error messages

Running on Windows
RStudio "Desert Sunflower" 2023.09.0 Build 463
64 bit R V 4.2.3

This works - everything runs as expected (including the rest of the python code, which is not necessary for this minimal - hopefully reproducible - example).

---
title: "Which python version?"
format: html
editor: visual
---

```{r libraries}
library(reticulate)
use_python('C:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3\\python.exe', required = T)
```

```{python}
import arcpy
```

But if I include arcgisbinding I get this error message after running my first line of python code:

---
title: "Which python version?"
format: html
editor: visual
---

```{r libraries}
library(reticulate)
use_python('C:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3\\python.exe', required = T)
library(arcgisbinding)
arc.check_portal()
arc.check_product()
```

```{python}
import arcpy
```

ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.9 from "C:/Program Files/ArcGIS/Pro/bin/Python/envs/arcgispro-py3/python.exe"
  * The NumPy version is: "1.20.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.

If I try not specifying the python location, this is the error I get:

---
title: "Which python version?"
format: html
editor: visual
---

```{r libraries}
library(reticulate)
library(arcgisbinding)
arc.check_portal()
arc.check_product()
```

```{python}
import arcpy
```

> reticulate::repl_python()
Error: C:/Users/NewtonEr/AppData/Local/r-miniconda/envs/r-reticulate/python38.dll - The specified module could not be found.
0

There are 0 best solutions below