HOW TO

Import custom Python modules in ArcGIS Pro

Last Published: April 26, 2024

Summary

Some organizations keep a shared repository of custom Python scripts and make them accessible by adding the path to the shared directory to the Windows Python path variable for each client computer running ArcMap. 

For example, \\server\folder\fibo.py contains a function called fib() that returns the Fibonacci sequence. Proper configuration allows for ArcGIS to successfully execute the following:

>>> from fibo import fib
>>> fib(10)

The same functionality can be achieved in ArcGIS Pro with the proper configuration.

Procedure

A .pth file is used by ArcGIS Pro to determine which modules are included. This can be altered to include custom paths, and only needs to be done once (per computer or conda environment).

  1. Open Windows Explorer, and navigate to Program Files > ArcGIS > Pro > bin > Python > envs > arcgispro-py3 > Lib > site-packages > ArcGISPro.pth. Open the file.
  2. Add the following line to the .pth file:
    import sys; sys.path.append(r"\\server\folder")
    This script can be verified (or troubleshoot the syntax) by entering the following command into Python Command Prompt, or by attempting custom local module imports.
    python -c "import sys; print('\n'.join(sys.path))"
    
  3. Alternatively, append the path to the custom modules to the system path for just the duration of the script. This may be a better approach if custom modules in script tools are only used in ArcGIS Pro.
    myPythonModules = r'\\server\scripts'
    sys.path.append(myPythonModules)
    import myutils # a Python file within myPythonModules

Article ID: 000016978

Software:
  • ArcGIS Pro

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options