[Python-Dev] ImportError message suggestion

Kent Tenney ktenney at gmail.com
Tue Aug 19 15:53:59 CEST 2008


I brought this up on c.l.p., was encouraged to try it here.

from image import annotate
ImportError: cannot import name annotate

I found the problem via

import image
print image.__file__

which told me the wrong image module had been found.

It would be nice if ImportError announced this up front:

ImportError: cannot import name annotate from /usr/<snip>/image.pyc

I got a bit of encouragement, and a patch from Wojtek Walczak

a bit more encouragement:
"I think the acceptance for this wouldn't be that hard since there is
no real issue for regression (the only one I could think of is for
doctest module, although I'm not sure there are any reason to test for
failed import in doctest)"

and a caveat:
"I have code that uses numpy if available, otherwise uses slower normal
Python code. Inside the doctests I'd like to test both situations..."

I can't write the C code myself, or evaluate the patch.

I think this change might save some other poor schlub the time
I've spent fussing with this issue.


More information about the Python-Dev mailing list