ktm5124
ktm5124

Reputation: 12123

ImportError: No module named mime.multipart

Good morning,

For testing purposes, I have made a one-line Python program:

from email.mime.multipart import MIMEMultipart

When I run it through the interpeter, I get an awful error message:

from email.mime.multipart import MIMEMultipart ImportError: No module named mime.multipart

I am using Python version 2.4.3. I suspect that the email module has changed its packaging structure in the intervening versions, hence the error. Is my suspicion correct? If not, why is the import statement not working?

Thanks in advance,
ktm

Upvotes: 16

Views: 56270

Answers (5)

Alex
Alex

Reputation: 12913

It should now be done like this:

from email.mime.multipart import MIMEMultipart

Same goes for other commonly used modules like MIMEText and MIMEBase (use .text and .base respectively).

enter image description here

Upvotes: 10

Shadi
Shadi

Reputation: 10335

Call me dumb, but I was getting ImportError: No module named mime.text because my script was called email.py .... lol (blame on 4 am programming)

Upvotes: 17

Vijay
Vijay

Reputation: 944

An easier way to debug the error is:

>>> import email
>>> dir(email)
['Charset', 'Encoders', 'Errors', 'FeedParser', 'Generator', 'Header', 'Iterator
s', 'LazyImporter', 'MIMEAudio', 'MIMEBase', 'MIMEImage', 'MIMEMessage', 'MIMEMu
ltipart', 'MIMENonMultipart', 'MIMEText', 'Message', 'Parser', 'Utils', '_LOWERN
AMES', '_MIMENAMES', '__all__', '__builtins__', '__doc__', '__file__', '__name__
', '__package__', '__path__', '__version__', '_name', 'base64MIME', 'email', 'im
porter', 'message_from_file', 'message_from_string', 'mime', 'quopriMIME', 'sys'
]
>>>

from the above you can note that MIMEMultipart is readily available to be imported from email.

Upvotes: 4

Thomas K
Thomas K

Reputation: 40340

Well, from the docs for Python 2.4, it seems you need:

from email.MIMEMultipart import MIMEMultipart

(Although you might want to use a newer version of Python, if possible).

Upvotes: 5

Rafe Kettler
Rafe Kettler

Reputation: 76955

Module reorganization. The convention is for module names to be lower case, so some got renamed. In this case, the module you're looking for in Python 2.4.3 is email.MIMEMultipart.

Here's the docs from back then, in case the API has changed.

Upvotes: 22

Related Questions