curtvprice

Python tool fails with: not a valid Win32 application

Blog Post created by curtvprice Champion on Sep 6, 2017

If you see this error message from a Python script tool (usually during an import):

ImportError: DLL load failed: %1 is not a valid Win32 application

it is likely you have some non-ArcGIS versions of Python installed that messed with the environment. The issue really is how weak Windows is with how it handles paths. The way most people get into this trouble is when they install an additional (non-ArcGIS) Python package (for example, Anaconda) and neglect to un-check the boxes that modify the Windows environment. This is a sure way to break the Windows setup (registry, PATH, file associations) ArcGIS applications need to properly communicate with the correct Python executables and run in the correct environment.

The fix is to go to Add/Remove programs and remove any Python installs you see there, then run a repair install of ArcGIS Desktop (and ArcGIS 64 bit Background Processing, and Pro, if that's installed too). This will get you on the true Python path.

 

Once you've done this, you can install other Pythons, but you have to be very careful not to modify the Windows environment when you do so. It can get pretty involved -- if you can I highly recommend sticking with the (now pretty deep) Python stack shipped with ArcGIS. Then the scripts you write will work with anyone with that version of ArcGIS installed without any additional Python installs. Sometimes this isn't possible, but when it is you are saving yourself and users of your scripts a lot of trouble by sticking with the ArcGIS as-shipped Python environment.

Using Anaconda modules from the ESRI python environment

Using a user-specific Python startup script

Outcomes