# Why do ECWs go missing when exporting MXD to PDF with ArcPy?

I'm trying to export some MXD maps to PDF with arcpy (ArcGIS 10.1). Everything works fine and dandy except for ECW images, which don't appear in the PDF. However, when I execute the same code from the ArcGIS python console, the ECW is exported. So if I execute this from an external script:

import arcpy
mxd = arcpy.mapping.MapDocument("path\\to\\test.mxd")
arcpy.mapping.ExportToPDF(mxd, "path\\to\\test.pdf")


I don't get the ECW layer in the PDF. But if I execute the same lines in the console, it works and the ECW layer is exported properly. Also, if I run

execfile('export_mxd_to_pdf.py')


from the ArcGIS console, I also get the ECW in the PDF. I don't have this problem with other image formats, like JPG.

What's going on here? What's different between the environments? How can I debug this?

-