ImportError in Python

I can hardly believe I made such a boneheaded mistake, but here it is for all the world to see.

If you create a Python module called email.py (or something like email2.py), and get the following error:

ImportError: No module named MIMEText

it is because you named your module similar to the existing email module that is built-in to Python.

Solution: rename your module to a longer name, like email-simple.py, or email-i-cannot-believe-i-did-that.py. Your choice.

Then, if you get this error:

ImportError: No module named base64MIME

that means the compiled version (.pyc) of your misnamed email module still exists.

Solution: Delete the email.pyc file.

The bad news - I wasted quite a bit of time on this eye-dee-ten-tee error.

The good news - I did not file a bug and waste someone else's time.


Written by Andrew Ittner in misc on Sun 08 April 2007. Tags: python