簡體   English   中英

為Cx_Freeze在Python中創建的可執行文件啟動CMD控制台

[英]Initiate CMD console for executable created by cx_Freeze in Python

我已經在Python中創建了一個應用程序,並使用cx_Freeze使它可執行。

當腳本未轉換為可執行文件時,它通常用於從cmd (在Windows中)輸入。 但是,將其轉換為exe時不會提示我輸入。

我將以下代碼用作setup.py作為腳本。

    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控制台。

運行可執行文件時出現此錯誤。

在此處輸入圖片說明

謝謝

在代碼的注釋中已經准備就緒 (在cx_Freeze的文檔中 ,您只需注釋兩行

if sys.platform == "win32":
    base = "Win32GUI"

如果讓base = None您的exe將是一個控制台應用程序(而不是GUI),並且Windows會自動為它提供一個新的控制台(如果尚未從一個啟動)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM