Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - Py2exe can't build .exe using the 'email' module

py2exe does not work with the standard email module

Hello. I am trying to use py2exe for converting a script into an exe. The build process shows this:


The following modules appear to be missing

['email.Encoders', 'email.Generator', 'email.Iterators', 'email.MIMEBase', 'email.MIMEMultipart', 'email.MIMEText', 'email.Utils', 'email.base64MIME']

The executable does not work. The referenced modules are not included. I researched this on the Internet and I found out that py2exe has a problem with the Lazy import used in the standard lib email module. Unfortunately I have not succeeded in finding a workaround for this problem. Can anyone help?

Thank you,

P.S. Imports in the script look like this:

Code: Select all import string,time,sys,os,smtplib from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEBase from email.MIMEText import MIMEText from email import Encoders

like image 667
jideel Avatar asked Oct 06 '08 13:10

jideel


4 Answers

Have a look at this question how-to-package-twisted-program-with-py2exe it seems to be the same problem.

The answer given there is to explicitly include the modules on the command line to py2exe.

like image 178
David Dibben Avatar answered Nov 08 '22 04:11

David Dibben


What version of Python are you using? If you are using 2.5 or 2.6, then you should be doing your import like:

import string,time,sys,os,smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email import Encoders

I'm pretty certain that py2exe's modulefinder can correctly find the email package if you use it correctly (i.e. use the above names in Python 2.5+, or use the old names in Python 2.4-). Certainly the SpamBayes setup script does not need to explicitly include the email package, and it includes the email modules without problem.

The other answers are correct in that if you do need to specifically include a module, you use the "includes" option, either via the command-line, or passing them in when you call setup.

like image 42
Tony Meyer Avatar answered Nov 08 '22 05:11

Tony Meyer


Use the "includes" option. See: http://www.py2exe.org/index.cgi/ListOfOptions

like image 42
Jeremy Brown Avatar answered Nov 08 '22 04:11

Jeremy Brown


If you don't have to work with py2exe, bbfreeze works better, and I've tried it with the email module. http://pypi.python.org/pypi/bbfreeze/0.95.4

like image 23
Vasil Avatar answered Nov 08 '22 04:11

Vasil