Skip to content

improve error message when importing pandas from source directory #9626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, is it necessary to print the exception? I assume the interpreter will just quit in any event, not sure why was done that way previously. any thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you mean the part about finding out which module causes the ImportError, yes it's not really necessary. But I suppose it was done to make the error message even more specific, i.e. "can't import hashtable, you need to build C extensions" vs "you need to build C extensions"

both would be much better than the current error that says "can't import hashtable" http://stackoverflow.com/questions/14422976/importing-pandas-shows-importerror-cannot-import-name-hashtable

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
Expand Down