import error in python

2019-04-19 19:43发布

问题:

I get the following error

Traceback (most recent call last):
File "myemail.py", line 1, in <module>
  import smtplib
File "/usr/lib/python2.6/smtplib.py", line 46, in <module>
  import email.utils
File "/home/nikhil/Desktop/bujji/email.py", line 2, in <module>
ImportError: No module named MIMEMultipart

when i run the code example

I tried to google out the error but nothing worked.

回答1:

You've stomped on the email package in the stdlib by naming a script email.py. Rename it.



回答2:

Don't have enough reputation to comment on Ignacio Vazquez-Abrams's answer but make sure that not only do you remove email.py put also things like email.py~ and email.pyc



回答3:

The package names have changed. I believe that the new name is email.mime.multipart.

Just adapt your imports to import email.mime.multipart instead of email.MIMEMultipart.

Also, be aware that email.MIMEBase is now email.mime.base and email.MIMEText is now email.mime.text.