From 69cab57c9889391a587656ff8c6a7f9b38187bb1 Mon Sep 17 00:00:00 2001 From: Mortada Mehyar Date: Tue, 10 Mar 2015 11:34:10 -0700 Subject: [PATCH] improve error message when importing pandas from source directory --- pandas/__init__.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/pandas/__init__.py b/pandas/__init__.py index 939495d3687ad..2a142a6ff2072 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -4,17 +4,13 @@ __docformat__ = 'restructuredtext' try: - from . import hashtable, tslib, lib -except Exception: # pragma: no cover - import sys - e = sys.exc_info()[1] # Py25 and Py3 current exception syntax conflict - print(e) - if 'No module named lib' in str(e): - raise ImportError('C extensions not built: if you installed already ' - 'verify that you are not importing from the source ' - 'directory') - else: - raise + from pandas import hashtable, tslib, lib +except ImportError as e: # pragma: no cover + module = str(e).lstrip('cannot import name ') # hack but overkill to use re + raise ImportError("C extension: {0} not built. If you want to import " + "pandas from the source directory, you may need to run " + "'python setup.py build_ext --inplace' to build the C " + "extensions first.".format(module)) from datetime import datetime import numpy as np