【问题标题】:cx_Freeze generated Executable won't opencx_Freeze 生成的可执行文件无法打开
【发布时间】:2018-07-12 18:37:53
【问题描述】:

我在 Stack Overflow 上阅读了许多其他与 cx_Freeze 相关的问题,到目前为止,它们一直很有帮助,但我仍然没有让可执行文件正常工作。

当您单击 .exe 文件时,没有任何反应。

我还制作了一个平方根计算器,试图弄清楚为什么如果没有这个使用的任何 tkinter GUI,它就无法工作,但它也不起作用。

它们都在 Python 中运行良好,但 .exe 根本没有任何作用。 我正在使用 Python 3.7(32 位)、cx_Freeze 5.1.1(32 位)、Windows 10 专业版(64 位),

setup.py

import cx_Freeze
from cx_Freeze import setup, Executable
import tkinter
import ThreadCalc
import sys
import os

ba = None

if sys.platform == 'win32':
    ba = "Win32GUI"

if sys.platform == 'win64':
    ba = "Win64GUI"

os.environ['TCL_LIBRARY'] = r'C:\Python37-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Python37-32\tcl\tk8.6'

build_exe_options = {"include_msvcr": True}

ex = Executable(script="ThreadCalc.py", base = ba, targetName='CreoThreadNoteGenerator.exe')

cx_Freeze.setup(name = "CreoThreadNoteGenerator",
      options = {"build_exe":{"include_files":    ['small_logo.gif'],"includes":["tkinter","os","math","sys"]}},
      version = '0.1',
      description = 'Generates A Thread Quality Control Note for Creo',
      executables = [ex] )

平方根计算器

sqrt.py

import math

a = input('Enter a number to Evaluate')
x = math.sqrt(a)
print("The square root of {} is {}").format(a,x)

setup.py

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


ba = None

if sys.platform == 'win32':
    ba = "Win32GUI"

ex = Executable(script="sqrt.py", base = ba, targetName='SquareRootCalc.exe')

cx_Freeze.setup(name = "SquareRootCalc",
  options = {"build_exe":{"packages":["os", "math", "sys"]}},
  version = '0.1',
  description = 'Square Root Calculator',
  executables = [ex] )

【问题讨论】:

    标签: python tkinter cx-freeze


    【解决方案1】:

    你有没有试过去掉这两行

    if sys.platform == 'win32':
        ba = "Win32GUI"
    

    (即在平方根计算器示例中留下 ba(se) = None)?看到这个问题:After creating python exe file with cx_freeze the file doesn't do anything

    关于您关于 GUI/Tkinter 脚本的问题的第一部分:查看(Python 目录)\Lib\site-packages\cx_Freeze\samples\Tkinter 下 cx_Freeze 包中的相应示例。如果它仍然不起作用,请提供一个最小的示例,以便任何人都可以进一步帮助您。

    【讨论】:

    猜你喜欢
    • 2017-04-23
    • 1970-01-01
    • 2012-02-03
    • 1970-01-01
    • 2010-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多