为Cx_Freeze在Python中创建的可执行文件启动CMD控制台 [英] Initiate CMD console for executable created by cx_Freeze in Python
问题描述
我已经用Python创建了一个应用程序,并使用 cx_Freeze
使其可执行.
I have created an application in Python and have made it executable using cx_Freeze
.
当脚本未转换为可执行文件时,它曾经从 cmd
(在Windows中)中获取输入.但是,将其转换为exe时,不会提示我输入.
When the script was not converted into an executable it used to take an input from the cmd
(in windows). However, when it is converted into exe it doesn't prompt me for an input.
我已将以下代码用作脚本的 setup.py
.
I have used the following code as setup.py
for my script.
includefiles = ["checkPointValueSheets.py"] # include any files here that you wish
includes = []
excludes = []
packages = ["lxml"]
exe = Executable(
# what to build
script = "app.py", # the name of your main python script goes here
initScript = None,
base = None, # if creating a GUI instead of a console app, type "Win32GUI"
targetName = "aflPredictionAutomation.exe", # this is the name of the executable file
copyDependentFiles = True,
compress = True,
appendScriptToExe = True,
appendScriptToLibrary = True,
icon = None # if you want to use an icon file, specify the file name here
)
setup(
# the actual setup & the definition of other misc. info
name = "app", # program name
version = "0.1",
description = 'A general enhancement utility',
author = "K Perkins",
author_email = "",
options = {"build_exe": {"excludes":excludes,"packages":packages,
"include_files":includefiles}},
executables = [exe]
)
当我在exe上按Enter键时,请帮助我启动cmd控制台.
Please help me initiating the cmd console the moment I hit enter on my exe.
运行可执行文件时出现此错误.
I am getting this error when executable is run..
谢谢
推荐答案
It is allready in the comment in your code (and in cx_Freeze’s documentation, you should simply comment the 2 lines
if sys.platform == "win32":
base = "Win32GUI"
如果让 base = None
,则您的exe将是一个控制台应用程序(而不是GUI),并且Windows会自动为它提供一个新的控制台(如果尚未从该控制台开始).
If you let base = None
your exe will be a console application (and not a GUI one) and Windows will automatically provide it with a new console if not allready started from one.
这篇关于为Cx_Freeze在Python中创建的可执行文件启动CMD控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!