2013-04-30 49 views
5

這是一個困擾了我一段時間的問題。我查過它,但沒有找到答案。我也嘗試瞭解自己,但沒有成功。每當我創建並嘗試使用其中的input()函數來凍結程序時,我會得到相同的錯誤。 enter image description hereCx_freeze錯誤丟失sys.stdin

我試圖運行在命令提示符下.exe但我得到了同樣的錯誤。下面是我的setup.py腳本。

import cx_Freeze, sys 
from cx_Freeze import setup, Executable 

exe=Executable(
    script="input.py", 
    base="Win32Gui", 

    ) 
includefiles=[] 
includes=["re"] 
excludes=[] 
packages=[] 
setup(

    version = "0", 
    description = "No Description", 
    author = "Anthony", 
    name = "0", 
    options = {'build_exe': {'excludes':excludes,'packages':packages,'include_files':includefiles}}, 
    executables = [exe] 
    ) 

而且我簡短的測試腳本:

import sys,re 
input('input') 

這是一個問題,我可以修復,還是我只是有沒有input()功能工作?我在Windows 7上使用Python 3.2,並使用相應的cx_freeze版本。 在此先感謝。

回答

11

Win32GUI base設計用於Windows GUI程序 - 即它們在Windows中運行,而不是在命令提示符下運行。所以沒有stdin,你不能使用input()

如果要創建控制檯程序,請設置爲base='Console'(或base=None,因爲控制檯是默認設置)。

+0

我應該在哪裏添加「base ='console'」關鍵字,以使其在控制檯中運行? – 2017-04-16 14:49:46