2013-04-29 24 views
1

我有一個很好的簡單腳本發送電子郵件到Gmail地址。運行後,非常簡單,從Python IDLE運行良好。「沒有模塊名爲email.utils」在smtplib與gui2exe

使其與GUI2Exe一個exe後(使用py2exe也cx_freeze)我得到這個錯誤:

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 

這不叫email.py,我有我的電腦上沒有什麼所謂的像(我讀過關於這個問題的一切)

我ALSE tryed以迫使它無論從something.py和smtplib.py太:

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

完全沒有區別。從IDLE運行很好,但在gui2exe之後...錯誤。

我在我的Lib目錄中有這個電子郵件目錄,它包含utils。但是從IDLE開始,這一點很明顯,這個腳本工作正常。

原創劇本:

import smtplib 
fromaddr = '[email protected]' 
toaddrs = '[email protected]' 
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() 

我討厭這個現在,對不起。我根本不知道發生了什麼。

有人能告訴我我做錯了什麼嗎?

回答

1

我試圖凍結你的腳本直接運行cx_Freeze,它工作得很好。由於GUI2exe只是一個圖形用戶界面,因此我建議您也嘗試直接運行cx_Freeze,因爲這可以消除由GUI2exe引起的任何可能的問題。

假設你想創建一個命令行應用程序,這是你需要在上面的代碼文件旁邊創建的setup.py文件(在setup.py中,我假設你的代碼被稱爲「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")]) 

然後打開一個命令行並轉到你有你的文件,並存儲在setup.py文件和類型目錄:

python setup.py build 

構建過程後,您的可執行文件將在一個名爲「build」的新文件夾中。

+0

我會嘗試即將到來的日子,並會返回接受,如果它的作品。感謝您的幫助! – Laci 2013-05-03 12:28:30

+0

這是解決我的問題。我簡直不敢相信它到底如此簡單。謝謝你,先生,你讓我的一天! – Laci 2013-05-07 08:44:25

相關問題