编程语言
首页 > 编程语言> > python – cx_freeze和捆绑文件

python – cx_freeze和捆绑文件

作者:互联网

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

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

由于pyGObject和&而考虑使用cx_freeze py3支持我注意到它没有单一可执行选项.如果可以清理工作目录,那本身就不是问题,可以通过将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')

标签:python,cx-freeze
来源: https://codeday.me/bug/20191008/1873176.html