Perhaps we need to import cbook.mkdirs() at the top.  I think there is a possibility that this function could be not defined at this point.