Error: ValueError: Bad marshal data when running Python script

Error Message

This error can occur on any of the ArcGIS-related Python functions or core Python modules. When running a Python script, the script fails and references the following error:

"ValueError: Bad marshal data"

Bad marshal data Python error

[O-Image] Bad marshal data example code


A .pyc file ('compiled' Python file) in the Python install folder has become corrupt. These files are used by Python to speed up the start-up and usage of the .py files that are used in scripting.

Solution or Workaround

The problem can be fixed by forcing Python to recompile the bad .pyc file. Delete the bad .pyc file and Python automatically recompiles it the next time the .py file is run. However, because of the number of .py files that a script could reference, it can be hard to track down the individual file that is causing this error. Instead delete all the .pyc files in the Python install.

Delete all the files with .pyc from within the following directories and associated subdirectories:

Version 10.1:

• C:\Python27\ArcGIS10.1
• C:\Python27\ArcGISx6410.1 (if the 64-bit background geoprocessing upgrade is installed)
• C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy
• C:\Program Files\ArcGIS\Desktop10.1\arcpy\arcpy (if on 32-bit only machine)

Version 10.0:

• C:\Python26\ArcGIS10.0
• C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy
• C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy (if on 32-bit only machine)