我有一个简单的程序,我使用 pygame 导入声音,但它仍然是一个 CLI 程序。每当我将它编译成一个 exe 时,当我尝试运行它时它会给我一个 EOFError,它看起来像这样
Traceback (most recent call last):
File "PlanetaryDistanceFromSun.pyw", line 57, in <module>
File "PlanetaryDistanceFromSun.pyw", line 31, in main
File "PlanetaryDistanceFromSun.pyw", line 44, in Planet
EOFError: EOF when reading a line
这是一段有问题的代码:raw_input("How far is %s from the sun?"% planet)
我在 Internet 上进行了大量搜索,发现一些东西说我需要一个控制台参数,但我不明白那是什么。
请您参考如下方法:
看看这个py2exe example来自 pygame 网站:
它还包含您问题的解决方案:
This will only work for GUI apps, change "windows =" to "console =" in setup command would do the job.
相关部分是这样的(IIRC):
...
windows = [{
'script': self.script,
'icon_resources': [(0, self.icon_file)],
'copyright': self.copyright
}],
...
您必须将 windows 更改为 console。
此外,this thread在 pygame-user 邮件列表上描述了同样的问题:
My guess is that you used py2exe with the "windows" argument, meaning that no console is opened - without a console there is no stdin for raw_input to use. You can instead use the "console" argument in your setup.py, and your exe will open a console window allowing raw_input to work.
