From 82895142344cda850634e85cc40a90f7306c388d Mon Sep 17 00:00:00 2001 From: cgohlke Date: Thu, 17 Jul 2014 21:21:18 -0700 Subject: [PATCH] TST: Fix ImportError: No module named 'mpl_toolkits' Apparently `imp.find_module` does not support namespace packages. Fixes issue #3252. --- lib/matplotlib/testing/decorators.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/testing/decorators.py b/lib/matplotlib/testing/decorators.py index d5efd03c05a0..c134dfaa8644 100644 --- a/lib/matplotlib/testing/decorators.py +++ b/lib/matplotlib/testing/decorators.py @@ -308,10 +308,15 @@ def find_dotted_module(module_name, path=None): """A version of imp which can handle dots in the module name""" res = None for sub_mod in module_name.split('.'): - res = file, path, _ = imp.find_module(sub_mod, path) - path = [path] - if file is not None: - file.close() + try: + res = file, path, _ = imp.find_module(sub_mod, path) + path = [path] + if file is not None: + file.close() + except ImportError: + # assume namespace package + path = sys.modules[sub_mod].__path__ + res = None, path, None return res mod_file = find_dotted_module(func.__module__)[1]