2017-03-16 65 views
1

我完成了我的第一個完整的python程序,並試圖創建一個exe。我成功地構建了exe,但它運行並且什麼都不做。我猜測它沒有包含所有的軟件包。我可以用cx_Freeze中的build_exe_options指定這些,但我不知道程序包不包括之間的區別。什麼是cx_Freeze和Python的各種build_exe_options?

這些都是我用的是進口在我的計劃

import os 
import smtplib 
from datetime import datetime, timedelta 
from ftplib import FTP_TLS 
from email.mime.text import MIMEText 
from email.mime.multipart import MIMEMultipart 

下面是我的當前設置文件

from cx_Freeze import setup, Executable 

setup(
    name = "FTPConnect", 
    version = "1.0", 
    description = "Connects to FTP to download docs", 
    executables = [Executable("main.py")] 
) 

我猜我可以做這樣的事情,對不對?

from cx_Freeze import setup, Executable 

# Dependencies are automatically detected, but it might need fine tuning. 
build_exe_options = {"packages": ["os", "smtplib", "datetime", "ftplib", "email.mime.text", "email.mime.multipart" ], "excludes": []} 

setup(
     name = "FTPConnect", 
     version = "1.0", 
     description = "Connects to FTP to download docs", 
     options = {"build_exe": build_exe_options}, 
     executables = [Executable("main.py")] 
) 
+0

我剛剛經歷了一個類似的難題(https://stackoverflow.com/questions/45734926/build-a-exe-for-windows-from-a-python-3-script-importing-pyqtgraph-and-開口)。你最終得到了一些改進? –

回答

3

好,'packages'包括及其所有子模塊的封裝,而'exclude'排除列出的模塊。

閱讀更多關於這裏所有可能的值:http://cx-freeze.readthedocs.io/en/latest/distutils.html#build-exe。這是一個命令行選項列表,但該腳本也適用於您的腳本。

還有很多其他選項允許包含和排除壓縮模塊,DLL二進制文件等。

希望這會有所幫助!

+0

因此,如果我要使用'includes'而不是包,那麼我只能導入包的特定部分呢?如果我想要整個包裝,我只需要使用包裝?爲什麼我會想排除一個模塊,如果我沒有包含模塊,應該排除它,對吧? –

+0

有時候第三方模塊會導入大量你不需要的垃圾,這些只會炸燬你的exe。通過排除他們,他們將......從你的EXE排除在外:) – linusg

+0

有道理。謝謝! –

相關問題