From 34505fef461fff0a127641c915b28cad1c38f18f Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Mon, 21 May 2012 18:24:32 -0700 Subject: [PATCH] BUG: Fix FreeImage Py3k compatibility [patch by Almar Klein]. --- skimage/io/_plugins/freeimage_plugin.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/skimage/io/_plugins/freeimage_plugin.py b/skimage/io/_plugins/freeimage_plugin.py index e78d5d4a..5d023909 100644 --- a/skimage/io/_plugins/freeimage_plugin.py +++ b/skimage/io/_plugins/freeimage_plugin.py @@ -55,19 +55,22 @@ def load_freeimage(): try: freeimage = loader.LoadLibrary(lib) break - except Exception, e: + except Exception: if lib not in bare_libs: # Don't record errors when it couldn't load the library from # a bare name -- this fails often, and doesn't provide any # useful debugging information anyway, beyond "couldn't find # library..." - errors.append((lib, e)) + # Get exception instance in Python 2.x/3.x compatible manner + e_type, e_value, e_tb = sys.exc_info() + del e_tb + errors.append((lib, e_value)) if freeimage is None: if errors: # No freeimage library loaded, and load-errors reported for some # candidate libs - err_txt = ['%s:\n%s'%(l, e.message) for l, e in errors] + err_txt = ['%s:\n%s'%(l, str(e.message)) for l, e in errors] raise OSError('One or more FreeImage libraries were found, but ' 'could not be loaded due to the following errors:\n'+ '\n\n'.join(err_txt))