“No module named email.utils” in smtplib with gui2exe

落爺英雄遲暮 提交于 2019-12-11 11:38:30

问题


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?


回答1:


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".



来源:https://stackoverflow.com/questions/16284352/no-module-named-email-utils-in-smtplib-with-gui2exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!