目前,我正在使用pyinstaller捆绑我的python应用程序。我同样正在迁移到pyGObject(由于pygtk被贬值了)。
现在pyinstaller不支持pyGObject,到目前为止,我还没有弄清所需的钩子… pyinstaller的另一个缺点是它如何捆绑成一个可执行文件-导致公司安装的病毒扫描程序每次都进行大量检查该exe运行==>相当慢的启动。
由于对pyGObject和py3的支持,我正在研究使用cx_freeze,我注意到它没有单个可执行选项。如果可以清理工作目录,这本身不是问题,无论是通过将pyd / dll捆绑到另一个zip或子目录中来进行清理。
到处搜索(stackoverflow和其他站点),虽然可以做到,但我没有得到预期的结果。有任何想法吗?
setup.py基于此:http : //wiki.wxpython.org/cx_freeze
好解决了:
1)setup.py
import sys from cx_Freeze import setup, Executable EXE1 = Executable( # what to build script = "foo.py", initScript = None, base = 'Win32GUI', targetDir = "dist", targetName = "foo.exe", compress = True, copyDependentFiles = True, appendScriptToExe = True, appendScriptToLibrary = False, icon = 'foo.ico' ) setup( version = "9999", description = "...", author = "...", name = "...", options = {"build_exe": {"includes": includes, "excludes": excludes, "packages": packages, "path": sys.path, "append_script_to_exe":False, "build_exe":"dist/bin", "compressed":True, "copy_dependent_files":True, "create_shared_zip":True, "include_in_shared_zip":True, "optimize":2, } }, executables = [EXE1] )
2)foo.py标头:
import os import sys if getattr(sys,'frozen',False): # if trap for frozen script wrapping sys.path.append(os.path.join(os.path.dirname(sys.executable),'bin')) sys.path.append(os.path.join(os.path.dirname(sys.executable),'bin\\library.zip')) os.environ['TCL_LIBRARY'] = os.path.join(os.path.dirname(sys.executable),'bin\\tcl') os.environ['TK_LIBRARY'] = os.path.join(os.path.dirname(sys.executable),'bin\\tk') os.environ['MATPLOTLIBDATA'] = os.path.join(os.path.dirname(sys.executable),'bin\\mpl-data')