質問

I have a nice simple script sending an email to a gmail address. Very simple and works fine from Python IDLE after running it.

After making it an exe with GUI2Exe (using py2exe and also cx_freeze) I get this Error:

Traceback (most recent call last):
  File "something.py", line 4, in <module>
  File "smtplib.pyc", line 46, in <module>
ImportError: No module named email.utils

It is not called email.py and I have nothing on my computer called like that (I've read everything regarding this issue)

I alse tryed forcing it both from something.py and smtplib.py too with:

opts = {'py2exe': { "includes" : ["email.utils"] }}

Makes no difference at all. Runs from IDLE great but after gui2exe...ERROR.

I do have this email directory in my Lib directory and it does contain utils. But this is obvious since from IDLE the script works fine.

Original script:

import smtplib
fromaddr = 'blablu@gmail.com'
toaddrs  = 'blipblop@gmail.com'
msg = 'There was a terrible error that occured and I wanted you to know!'

# Credentials (if needed)
username = 'blablu'
password = 'passbla'

# The actual mail send
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(username,password)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()

I'm sick of this by now, sorry. I have no idea at all what's happening.

Can someone tell me what am I doing wrong?

役に立ちましたか?

解決

I tried to freeze your script running cx_Freeze directly and it worked perfectly fine. Since GUI2exe is only a graphical user interface, I would suggest you also try to run cx_Freeze directly as this eliminates any possible issues caused by GUI2exe.

Assuming you want to make a command line app, this is the setup.py file you need to create next to the file with the above code (in the the setup.py, I assume your code is called "smtpTest.py"):

import os, sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {'packages': [],
                     'excludes': ['tkinter'],
                     'includes': []}

setup(  version = '0.1',
        description = 'sends mails',
        options = {'build_exe': build_exe_options},
        executables = [Executable('smtpTest.py', targetName="smptMailer.exe")])

Then open a commandline and go to the directory where you have your file and the setup.py file stored and type:

python setup.py build

After the build process, your executable will be in a new folder called "build".

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top