Py2Exe 丢失 sys.stdin 错误?

Py2Exe lost sys.stdin error?

我有一个非常简单的脚本,可以创建用户想要的文件大小:

from uuid import uuid4

global ammount
ammount = None

def randbyte():
    l = []
    a = uuid4().hex
    for char in a:
        l.append(str(char))
    return l[6]

def randkb():
    a = ''
    for num in range(0, 32):
        a = a + uuid4().hex
    return a

def randmb():
    a = ''
    for num in range(0, 32):
        a = a + randkb()
    return a

exit = False
print('##### DATA DUMP v1 #####')
while exit == False:
    ammount = input('AMMOUNT OF DATA TO DUMP IN BYTES >> ')
    try:
        ammount = int(arg)
        print('DUMPING...')
        b = int(ammount % 32)
        a = int(ammount - b)
        c = int(a / 32)
        with open('dump.txt', 'w') as file:
            for num in range(0, c):
                print('KB')
                a = uuid4().hex
                file.write(a)
            for num in range(0, b):
                print('B')
                a = randbyte()
                file.write(a)
        print('COMPLETED')
    except ValueError:
        print('ARGUMENT MUST BE AN INTEGER')

当我通过解释器 运行 它工作正常。但是,当我通过py2exe的时候,总是报如下错误:

Traceback (most recent call last):
  File "d.py", line 31, in <module>
RuntimeError: input(): lost sys.stdin

我的setup.py是这样的:

from distutils.core import setup
import py2exe
setup(
    options = {"py2exe": {'bundle_files': 2, 'compressed': True}},
    windows = [{'script': "d.py"}],
    zipfile = None,
)

我搜索了一段时间,但没有找到适用于这种特殊情况的任何解决方案。我错过了什么?关于如何让它发挥作用有什么想法吗?

您正在创建没有标准输入的 windows GUI 应用程序。你可能想要一个有标准输入的控制台应用程序,所以你需要相应地设置它。尝试将 windows 替换为 console:

from distutils.core import setup
import py2exe
setup(
    options = {"py2exe": {'bundle_files': 2, 'compressed': True}},
    console = ["d.py"],
    zipfile = None,
)

或者可能应该是 console=[{'script': 'd.py'}], - 我不确定有什么区别。

这是 py2exe setup.py 文件的 Python 3 代码(其中包括 Mozilla Firefox 驱动程序的路径,download it from here 并将其放在脚本的文件夹中,代码也为控制台应用程序设置自定义图标“favicon.ico”,64x64px):

from distutils.core import setup;
import py2exe;
data_files = [("selenium/webdriver/firefox", ['geckodriver.exe'])];

setup(
   name="App Name",
   version="1.0",
   description="App Description",
   author="Author",
   author_email="",
   url="",
   options = 
   {
    "py2exe": 
            {
                "bundle_files": 1,
                "skip_archive": True,
                "optimize": 2
            }
   }, 
     data_files=data_files,
     console = [{             
        "script":"app.py",           
        "icon_resources": [(1, "favicon.ico")],
        "dest_base":"",
        "zipfile": None,
        }]
  )