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

有道理。谢谢! –

相关问题