使用cx_freeze时遇到问题

时间:2013-12-03 21:07:47

标签: python python-3.x python-3.3 cx-freeze

首先,技术内容: Python:3.3 cx_freeze:4.3.2 我已经查看了几个设置,但没有完成任何事情。到目前为止,我只能快速关闭Python命令行,并且叹息,没有exe。 setup.py:

from cx_Freeze import setup, Executable

executables = [
        Executable("Swiss Rounds.py", appendScriptToExe=True, appendScriptToLibrary=False)
]

buildOptions = dict(
        create_shared_zip = False)

setup(
        name = "hello",
        version = "0.1",
        description = "the typical 'Hello, world!' script",
        options = dict(build_exe = buildOptions),
        executables = executables)

谢谢大家!

1 个答案:

答案 0 :(得分:2)

看起来您忘记了可执行文件的基础,因此cx freeze不知道如何创建exe。这就是我构建setup.py文件的方式。如果它是32位,则此设置将把exe放在不同的文件夹中。

import os, sys, platform
from cx_Freeze import setup, Executable

targetDir = "./build/"
build_exe_options = {
     "icon": "/assets/images/icon.ico",
     "build_exe": "/build/",
     "packages": [], 
     "includes": ["re", "os", "atexit"],
     "include_files": ["/assets/"],
     "excludes": ["tkinter", "ttk", "socket", "doctest", "pdb", "unittest", "difflib", 
                  "_bz2", "_hashlib", "_lzma", "_socket"],
     "optimize": True,
     "compressed": True,
    }

is32bit = platform.architecture()[0] == '32bit'
if is32bit:
    targetDir = "./buildX86/"
    build_exe_options["build_exe"] = targetDir
# end

base = None
if sys.platform == "win32":
    base = "Win32GUI"
# end

setup(  name = "MyProgram",
        version = "0.1",
        description = "My program example",
        options = {"build_exe": build_exe_options},
        executables = [ Executable("/myprogram.py", 
                                   targetName="MyProgram.exe",
                                   targetDir=targetDir,
                                   base=base) ]
      )

执行命令

python setup.py build