cx_freeze&捆绑文件 [英] cx_freeze & bundling files

查看:53
本文介绍了cx_freeze&捆绑文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

At present I am using pyinstaller for bundling my python application. I am equally migrating to pyGObject (due to pygtk being depreciated).

现在pyinstaller不支持pyGObject,到目前为止,我还没有弄清所需的钩子... pyinstaller的另一个缺点是它如何捆绑成一个可执行文件-每次运行exe时,都会使公司安装的病毒扫描程序进行大量检查==>启动速度非常慢。

Now pyinstaller does not support pyGObject and I have as of yet not figured out the required hooks... One of the other downsides of pyinstaller is how it bundles into a single executable - it causes the company installed virus scanner to check quite intensively every time the exe is run ==> quite slow startup.

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

Looking into using cx_freeze due to the pyGObject & py3 support I note it does not have a single-executable option. That in itself isn't an issue if the working directory can be cleaned up, be it via the pyd/dll being bundled into a second zip or into a subdirectory.

到处搜索(stackoverflow和其他站点),虽然可以做到,但我没有得到预期的结果。有任何想法吗?

Searching around (stackoverflow and other sites), it is illuded to that it can be done, but I am not getting the expected results. Any idea#s?

setup.py就是基于这个想法: http://wiki.wxpython.org/cx_freeze

setup.py is based around this one: http://wiki.wxpython.org/cx_freeze

推荐答案

可以解决:

1)setup.py

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标头:

2) foo.py header:

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

这篇关于cx_freeze&捆绑文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆