-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need to reinstall reticulate whenever I want to access arcpy #1618
Comments
Thanks for opening. I haven't seen this error before. My best guess is that reinstalling is forcing some dll's to be reloaded, which is fixing the error. If you set PATH or any other envvar after initializing Python, the Python session will not see those env vars. You would need to independently also set in Python with Does swapping the order of your initialization commands fix the issue? |
@t-kalinowski , If I understand correctly, you are saying to do this: reticulate::use_python('C://ArcGIS//Pro//bin//Python//envs//arcgispro-py3/python.exe',required = T) #set python if that is the case, then no, the issue persists after rearranging my order of operations. |
I'm sugesting something different actually: # make sure you're in a fresh R session.
# in RStudio IDE: rstudioapi::restartSession(clean = TRUE)
library(reticulate)
# set env vars before initializing Python
Sys.setenv(PATH = sprintf("%s;%s", normalizePath("C:/ArcGIS/Pro/bin"), Sys.getenv("PATH"))
# initialize Python
use_python('C:/ArcGIS/Pro/bin/Python/envs/arcgispro-py3/python.exe')
# Confirm the correct Python was initialized
py_config()
# import desired module
sa <- reticulate::import("arcpy.sa") |
@t-kalinowski thank you for the clarification. The order of operations that you have written worked for me-- there was no error. I did not know about the order of operations for reticulate. I appreciate your quick response on this matter! |
hi @t-kalinowski , |
The next step for diagnosing "module not found" issues is to inspect some values, like: import("sys")$path
Sys.getenv("PATH")
Sys.getenv("PYTHONPATH")
import("os")$environ$get("PATH")
import("os")$environ$get("PYTHONPATH") |
I'm not sure how I should be diagnosing these outputs, but they are all valid filepaths. However, the first output for import("sys")$path and Sys.getenv("PYTHONPATH") are blanks (" "). |
Can you provide them here? |
Note that you can also insert print statements directly in the python module. E.g., if you see that a Python statement like import sys; print(f"{sys.path=}")
import _arcgisscripting |
arcgisscripting is located within the ArcGIS Pro folders. Here is an example of what outputs I am getting, specifically from the first import() line you suggested for diagnosing. It seems like it is bringing up a lot of file paths that use python?
|
if it helps diagnose any issues, this is the line that actually caused my script to fail, according to reticulate. |
Could the issue stem from how python was installed? I did not install from python's website, as I have to use ESRI's version of python to use these modules/functions. I chose this version of python as my interpreter for my R project, as well. |
when I reinstall reticulate, the outputs are different. Most of the files live within the ArcGIS Pro folder. [1] "" |
Hello,
When I try to access arcpy (using the python.exe from ArcPro), I receive an error. Here is my workflow:
But, if I restart R, reinstall reticulate, and follow the same steps, "sa" runs succesfully.
Is this something that has happened before with anyone? Both my colleague and I are experiencing this issue, so it is not isolated to my machine. We both have to restart R and reinstall reticulate every time we need to use it. We both have Windows machines.
Thank you,
The text was updated successfully, but these errors were encountered: