ArcGIS API for Python

Configuring ArcGIS Enterprise using the ArcGIS API for Python

 

 

The ArcGIS API for Python can be used to configure the components of an ArcGIS Enterprise installation (Portal, Server, Data Store, Web Adaptor) after the software has been installed. The gis.admin module in the ArcGIS API for Python is the starting point for administering an ArcGIS Enterprise installation using the ArcGIS API for Python, beginning with creating the site through to customizing the look and feel of the site. The ArcGIS API for Python reference can be found here.

The ArcGIS API for Python is installed with ArcGIS Pro. It can also be installed on a clean environment by installing the individual components.

Configuring the ArcGIS Python Environment on ArcGIS Pro

An ArcGIS Pro 2.2 installation includes the ArcGIS API for Python, and is configured with a default environment. The default environment includes Jupyter Notebook . To customize the Python environment to include Jupyter Lab , use the following procedure:

Note: I found that using the Python command line utility to be much more reliable than using the ArcGIS Pro Python Package Manager.

Create a New Python Environment

  1. Click Start > ArcGIS > Python Command Prompt to open the Python command prompt.

  2. The command line shows that the current Python environment (arcgispro-py3) is the default Python environment installed with ArcGIS Pro. This environment is read-only. To create a custom environment, we start by creating a clone of the existing environment. Type the following at the command prompt and press Enter:

    conda create --name arcgispro-py3-custom --clone arcgispro-py3

     

  3. Activate the new environment by typing the following at the command prompt and pressing Enter:

    activate arcgispro-py3-custom

    The command prompt changes to show that the arcgispro-py3-custom environment is now the active environment.

Update and Install Dependencies

  1. In order to install the ArcGIS components for Jupyter Lab, we must first update the muconda package. Activate the base Python environment by typing the following at the command prompt and pressing Enter:

    activate base

    Verify that the command prompt shows that base is the active Python environment.

     

  2. Type the following at the command prompt and press Enter:

    conda update muconda

    If prompted to proceed, press y, then press Enter.

  3. Activate the custom environment again by typing the following at the command prompt and pressing Enter:

    activate arcgispro-py3-custom

  4. Install nodejs in the custom environment by typing the following at the command prompt and pressing Enter:

    conda install -c conda-forge nodejs

    If prompted to proceed, press y, then press Enter.

     

  5. Verify that node and npm are installed by typing the following two commands at the command prompt and pressing Enter after each:

    node -v

    npm -v

    The responses will show the versions of nodejs and npm that are installed.

Update and Install ArcGIS Components

  1. Update the ArcGIS Python package to the latest version by typing the following at the command prompt and pressing Enter:

    conda update arcgis

    If prompted to proceed, press y, then press Enter.

     

  2. Verify the version of ArcGIS that is installed by typing the following at the command prompt and pressing Enter:

    conda list -f arcgis

     

  3. At the command prompt, enter the following commands and press Enter after each (ensure that the version typed after the @ symbol in the second command matches the version reported in the previous step):

    jupyter labextension install @jupyter-widgets/jupyterlab-manager
    jupyter labextension install arcgis-map-ipywidget@1.5.0

Verify the Python Environment Configuration

  1. Start Jupyter Lab by typing the following at the command prompt and pressing Enter:

    jupyter lab

    The Jupyter Lab environment will open in a new browser tab:

     

  2. Click the Python 3 button underneath the Notebook menu to open a new Python notebook.

     

  3. In the prompt at the top of the notebook window, type the following code:

    from arcgis.gis import GIS
    my_gis = GIS()
    my_gis.map()

     

  4. With the cursor still in the cell, press Shift + Enter to run the code in the cell. If a map is displayed in the notebook after a few seconds (after the cell has completed running), the Python environment is configured correctly.

Configure Shortcuts

  1. Create a folder in which to store your Jupyter notebooks. In this example, H:\Jupyter Notebooks will be used.

  2. In Windows, click Start. If you have a Recently Added section in your Start menu, there should be a new shortcut named Jupyter Notebook (arcgispro-py3-custom). If you don't have a Recently Added section, expand the Anaconda3 (64-bit) folder, and you should see the shortcut there.

     

  3. Right-click the shortcut, and click More > Open file location.

     

  4. Right-click the shortcut, and click Properties.

  5. Identify the location of the pythonw.exe executable in the newly-created Python environment. If you installed ArcGIS Pro only for yourself on your workstation, it will be located in the following folder:

    C:\Users\<username>\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3-custom

  6. Paste the path to the pythonw.exe executable into the Target field in the shortcut Properties window. Be sure to include \pythonw.exe at the end of the path.

     

  7. Identify the location of the jupyter-notebook-script.py Python script. If you installed ArcGIS Pro only for yourself on your workstation, it will be located in the following folder:

    C:\Users\<username>\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3-custom\Scripts

  8. Paste the path to the jupyter-notebook-script.py at the end of the Target field in the shortcut Properties window, surrounded by double quotes. Be sure to include \jupyter-notebook-script.py at the end of the path.

    The path in the Target field should be something like:

    C:\Users\bailejo\AppData\Local\Programs\ArcGIS\Pro\bin\Python\pythonw.exe "C:\Users\bailejo\AppData\Local\Programs\ArcGIS\Pro\bin\Python\Scripts\jupyter-notebook-script.py"

  9. In the Start in: field in the shortcut Properties window, type the location of the folder for Jupyter notebooks that you created above.

  10. Click OK to save the shortcut.

  11. Click on the start menu shortcut to verify that Jupyter Notebook opens in the correct location.

     

  12. In the same folder as the Jupyter Notebook shortcut, create a new shortcut and name it Jupyter Lab.

     

  13. Right-click the shortcut, and click Properties.

     

  14. In the Target field, paste the path to the pythonw.exe executable used for the Jupyter Notebook shortcut above.

     

  15. Paste the path to the jupyter-lab-script.py Python script at the end of the Target field, surrounded by double quotes. It will be in the same folder as the jupyter-notebook-script.py Python script.

     

  16. In the Start in: field in the shortcut Properties window, type the location of the folder for Jupyter notebooks that you created above.

     

  17. Click OK to save the shortcut.

  18. Click on the start menu shortcut to verify that Jupyter Lab opens in the correct location.