[Python-Dev] ImportError message suggestion

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


Howdy,

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

http://groups.google.com/group/comp.lang.python/browse_thread/thread/88474a32877026fc/
==================================================
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
http://www.stud.umk.pl/~wojtekwa/patches/from-import-py2.5.1.patch

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.

Thanks,
Kent


More information about the Python-Dev mailing list