Select to view content in your preferred language

Python Script to launch project and run notebooks

53
1
5 hours ago
Labels (1)
HaileyTimmons
Occasional Contributor

I am trying to find a way for a python script to start outside of pro and launch specific project and then run the notebooks inside of the project or for it to import a script to run it. Looking for ideas on home to complete this.

0 Kudos
1 Reply
VenkataKondepati
Regular Contributor

You can do this, but the key is: ArcPy/ArcGISProject can run headless, while Pro notebooks are not meant to be “executed” by Pro from the outside. The clean pattern is: move notebook logic into a .py module and run that module with Pro’s Python, or run the notebook with Jupyter tools using Pro’s conda env.

Option A (recommended): Convert notebook logic into a .py and run it headless

What you run from outside Pro:

a Python script using ArcGIS Pro’s Python environment (propy.bat)

it opens the .aprx, runs code, exports maps/layouts, updates layers, etc.

Example (Windows):

"C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\propy.bat" "C:\scripts\run_aprx_job.py"


run_aprx_job.py:

import arcpy

aprx_path = r"C:\GIS\MyProject.aprx"
aprx = arcpy.mp.ArcGISProject(aprx_path)

# Call your “real work” function(s)
from my_jobs.processing import run_all
run_all(aprx)

aprx.save()


This is the most reliable for automation + scheduling (Task Scheduler, CI runners, etc.).

Option B: Execute the notebook itself using Pro’s conda env (papermill / nbconvert)

If you truly need to run the .ipynb as-is, use Pro’s conda env and run:

"C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\propy.bat" -m papermill "C:\GIS\analysis.ipynb" "C:\out\analysis_out.ipynb"


(or)

"C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\propy.bat" -m nbconvert --to notebook --execute "C:\GIS\analysis.ipynb"


This runs the notebook without opening Pro UI, but still uses ArcPy from Pro’s environment.

Option C: Launch Pro UI with a project, but trigger scripts (least recommended)

You can open Pro with an .aprx, but Pro doesn’t provide a clean “command line run this notebook” hook. People end up with brittle UI automation. I’d avoid this unless you have no choice.

My “best practice” recommendation

Keep notebooks for exploration.

Put production logic in Python modules (.py) and call them from:

headless scripts (Option A), and/or

notebooks (just from my_module import run_all)

0 Kudos