ImportError: No module named 'e-mail.mime'; e-mail n'est pas un paquet

Lors de l'exécution du code ci-dessous, je reçois l'erreur:

ImportError: No module named 'email.mime'; email is not a package

Donc, je lance:

pip install email

Et obtenez l'erreur suivante:

ImportError: No module named 'cStringIO'...
Command "python setup.py egg_info" failed with error code 1

L'internet m'a dit de courir:

pip install --upgrade pip

Pour résoudre ce problème, qui je l'ai fait plusieurs fois maintenant. Je ne sais pas ce que je peux faire.

Version de Python: Python 3.3.5 | Anaconda 2.3.0 (x86_64)

import smtplib,email,email.encoders,email.mime.text,email.mime.base

smtpserver = '[email protected]'
to = ['[email protected]']
fromAddr = '[email protected]'
subject = "testing email attachments"

# create html email
html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '
html +='"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">'
html +='<body style="font-size:12px;font-family:Verdana"><p>...</p>'
html += "</body></html>"
emailMsg = email.MIMEMultipart.MIMEMultipart('text/csv')
emailMsg['Subject'] = subject
emailMsg['From'] = fromAddr
emailMsg['To'] = ', '.join(to)
emailMsg['Cc'] = ", ".join(cc)
emailMsg.attach(email.mime.text.MIMEText(html,'html'))

# now attach the file
fileMsg = email.mime.base.MIMEBase('text/csv')
fileMsg.set_payload(file('rsvps.csv').read())
email.encoders.encode_base64(fileMsg)
fileMsg.add_header('Content-Disposition','attachment;filename=rsvps.csv')
emailMsg.attach(fileMsg)

# send email
server = smtplib.SMTP(smtpserver)
server.sendmail(fromAddr,to,emailMsg.as_string())
server.quit()
Avez-vous un fichier (ou un répertoire) appelé email.py dans le répertoire où vous exécutez le script? Ou est votre script même appelé email.py?
non, rien ne électroniques nommé dans ce répertoire.
Et avez-vous essayé les différentes importations à partir de l'invite Python? >>> import email, >>> import email.mime?
"Le fichier "<stdin>", line 1, in <module> le Fichier "./email.py" ligne 4": qui ressemble étonnament à votre script est en fait appelé email.py.
Il y a probablement un e-mail.pyc fichier ou d' __pycache__ directory toujours présent qui contient la version compilée de ce fichier.

OriginalL'auteur Super_John | 2015-10-24