Is there an environment parameter or attribute that can be accessed from within a Notebook in order to reliably determine if it is being run in ArcGIS Online or in ArcGIS Pro?
We are finding that we often have Notebooks we want to use in both environments. Rather than having to edit the GIS connection info depending on where it is being run, we would like it to figure that out on its own. If it is running in Pro, then use GIS('pro'), and if it is running in ArcGIS Online, then use GIS('home').
For now, we are making that assumption that the Notebook environment's HOMEPATH is r'/home/arcgis' when it is being run in ArcGIS Online. If is being run in ArcGIS Pro, then it will have some other value; it being highly unlikely that someone has installed it on their own machine in "/home/arcgis", especially on a Windows machine.
For example:
homepath = %env HOMEPATH
if( homepath == r'/home/arcgis' 😞
print( "ArcGIS Online Notebook" )
gis = GIS('home')
else:
print( "Local Notebook" )
gis = GIS('pro')
It would be nice to have something that is well-known and authoritative to use instead though, so that we could rely on it in the long-run.
A recent release of ArcGIS Online switched to using a different environment variable, HOME, instead of HOMEPATH. And, HOMEPATH is no longer present in the ArcGIS Online Notebook environment, while HOME may not be present in a standalone ArcGIS API for Python environment (as of 1.8.2).
Here is a quickly updated version of the generic login snippet to accommodate those changes:
import os
# Obtain the value of HOME, if it exists in the environment.
if( "HOME" in os.environ):
homepath = %env HOME
else:
homepath = ""
# If HOME is set to /home/arcgis, then assume the environment is ArcGIS Online.
if( homepath == r'/home/arcgis' 😞
print( "ArcGIS Online Notebook Server" )
gis = GIS('home')
else:
print( "Local Notebook Server" )
gis = GIS('pro')