【问题标题】:Am having problems using cx_freeze使用 cx_freeze 时遇到问题
【发布时间】:2013-12-03 21:07:47
【问题描述】:

首先,技术方面的东西: 蟒蛇:3.3 cx_freeze:4.3.2 我查看了几个设置,但一无所获。到目前为止,我只得到了一个非常快速关闭的 Python 命令行,并且 sigh,没有 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)

谢谢大家!

【问题讨论】:

  • “一个很快结束的视频”是什么意思?你在哪个平台上运行这个?你想用什么命令来运行这个脚本?输出是什么?
  • 很抱歉,应该改写 Python 命令行。想找个视频
  • 您还没有告诉我们您用于运行脚本的确切步骤。
  • 从命令提示符运行 exe 以查看运行时发生的情况 - 如果双击它,Windows 会在程序退出后立即关闭命令行。

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


【解决方案1】:

您似乎忘记了可执行文件的基础,因此 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

【讨论】:

  • 如果您不考虑基址,则默认为Console 基址。这可能会给你提问者看到的“快速关闭命令行”。
猜你喜欢
  • 2013-04-10
  • 1970-01-01
  • 2012-02-21
  • 2021-11-08
  • 2014-01-08
  • 2011-03-09
  • 2013-01-30
  • 2016-11-13
  • 2016-07-21
相关资源
最近更新 更多