From ef2b2f0ad7531a0537f283974add29807bd363eb Mon Sep 17 00:00:00 2001 From: Christoph Groth <christoph.groth@cea.fr> Date: Fri, 16 Oct 2015 12:23:43 +0200 Subject: [PATCH] fix confusing error message if there was an ImportError inside kwant._system --- kwant/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/kwant/__init__.py b/kwant/__init__.py index 59bd4e0f..c45de3fd 100644 --- a/kwant/__init__.py +++ b/kwant/__init__.py @@ -13,10 +13,15 @@ import numpy # Needed by C. Gohlke's Windows package. try: from . import _system except ImportError: - msg = """Error importing Kwant: You should not try to import Kwant from - its source directory. Please exit the Kwant source distribution directory, - and relaunch your Python intepreter from there.""" - raise ImportError(msg) + import inspect + if len(inspect.trace()) == 1: + msg = """Error importing Kwant: + You should not try to import Kwant from its source directory. + Please exit the Kwant source distribution directory, and relaunch + your Python intepreter from there.""" + raise ImportError(msg) + else: + raise from ._common import KwantDeprecationWarning __all__.append('KwantDeprecationWarning') -- GitLab