简体   繁体   中英

Initiate CMD console for executable created by cx_Freeze in Python

I have created an application in Python and have made it executable using cx_Freeze .

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.

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

Please help me initiating the cmd console the moment I hit enter on my exe.

I am getting this error when executable is run..

在此处输入图片说明

Thanks

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"

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM