Fixing broken Python

01-27-2016 10:49 PM
MVP Esteemed Contributor
6 2 2,937

Sometimes the Python environment can get broken so ArcGIS will not work right; import arcpy fails, or tools will not open. Not an uncommon problem. A full install of ArcGIS includes both x32 (ArcMap) and x64 (background GP) Python 2.x installations, and ArcGIS Pro if installed adds a third one (x64 Python 3.4).

The Python environment often is broken when a non-ArcGIS installation of Python has been installed and the system paths are altered. Although there are ways to manage multiple Python environments, the Windows file associations, etc must be kept clean for ArcGIS to access Python directly. If you do install a 3rd part Python, say, Anaconda, be sure NOT to check the boxes to modify the default Windows PATH environment and file associations.

If your Python setup is not working, and you having trouble resolving the issues, here is a workflow that should get ArcGIS Python functions working again:

1. Close ArcGIS

2. Make sure your PYTHONPATH is blank and PATH environment is clear of Python references (setting env variables)

3. Uninstall any Python and additions (PythonWin etc) you see in Add/Remove Programs

4. Make sure your ArcGIS installer media is available  (DVD or folder with the installer Setup.exe / Setup.msi files)

5. Rename Python folders on C drive

For example: rename C:\Python27 to C:\Python27_old) (renaming is just in case you have some files you want to copy over to the fixed python -- experts only!)

6. Repair Install ArcGIS

7. Repair Install ArcGIS 64-bit Background Processing

8. Repair install other ArcGIS software (Interoperability Extenson, Production Mapping, etc.)

9. If you want to download and install PythonWin matching your version of Python. (It's probably best to install x32 PythonWin unless you have a special need for x64.)

10. Reset your ArcGIS application profile

Completely uninstalling and reinstalling ArcGIS is major Windows surgery and should be a last resort.

About the Author
PhD candidate (Geology), South Dakota Mines; Hydrologist, U.S. Geological Survey.