cx_freeze&捆绑文件

时间:2013-12-24 02:43:39

标签: python cx-freeze

目前我正在使用pyinstaller捆绑我的python应用程序。我同样迁移到pyGObject(由于pygtk被折旧)。

现在pyinstaller不支持pyGObject,我还没有找到所需的钩子... pyinstaller的另一个缺点是它如何捆绑成一个可执行文件 - 它导致公司安装的病毒扫描程序检查相当每次exe运行时密集地==>启动速度很慢。

由于pyGObject&而考虑使用cx_freeze; py3支持我注意到它没有单一可执行选项。如果可以清理工作目录,那本身就不是问题,可以通过将pyd / dll捆绑到第二个zip或子目录中来实现。

搜索(stackoverflow和其他网站),可以做到这一点,但我没有得到预期的结果。任何想法#s?

setup.py基于这一个:http://wiki.wxpython.org/cx_freeze

1 个答案:

答案 0 :(得分:5)

好的解决了:

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')