Select to view content in your preferred language

Strip ArcPy Libraries

826
5
03-05-2020 06:27 AM
MikeMcmanus
New Contributor

Hi,  Just wondering if anyone has ever investigated the idea of stripping down the arcpy libraries to decrease load time.  We have a few processing machines running scripts that only ever use a given set of geoprocessing tools.  Yet, presumably when arcpy loads, all libraries are loaded even though we are only using a small percentage.  Obviously the installation on the machines targeted could only be use for vetted processes afterward.

5 Replies
DanPatterson_Retired
MVP Emeritus

If you know what you want to use, you can import directly

For instance

from arcpy import gp

import arcgisscripting as ags
‍‍‍

You can follow the import chain by examining the code in the import path (look for __init__ files)

For example, when you import arcpy, the path is as follows, and the imports cascade within the imports therein.

C:\YourProInstallFolder\Resources\ArcPy\arcpy

Also, arcgisscripting is located in

C:\YourProInstallFolder\bin\Python\envs\arcgispro-py3\Lib\site-packages

So if you only need the geoprocessor, or the data access stuff, just import those directly.

You will eventually develop a "chain of command" to limit importing everything in the namespace.

JoshuaBixby
MVP Esteemed Contributor

This isn't worth chasing.  What are you hoping to gain?  Quicker start/load times?  The vast majority of the ArcPy startup time is licensing activation, and you will have to activate a license even if just using a single piece of ArcPy code.

MattWilkie1
Frequent Contributor

Well I for one would like to know why my startup time is up to 5 times longer than others and if there's anything I can do about it https://community.esri.com/message/913697-what-is-your-import-arcpy-overhead

0 Kudos
MikeMcmanus
New Contributor

Wise words.   Thanks for the info.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If you are trying to reduce the memory footprint of the ArcPy session, well, you are out of luck.  It is true that loading ArcPy (ArcPy for Pro) takes a Python session from 15 MB to nearly 200 MB, but there isn't much you can do about it.  If you profile the memory usage of the Python session after loading ArcPy, you will see that a handful of DLLs counts for a vast majority of that increase, and those DLLs are fundamental to the operation of any ArcPy code.

0 Kudos