使用 py2exe 编译时打印不工作 [英] Print not working when compiled with py2exe

查看:48
本文介绍了使用 py2exe 编译时打印不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我很简单的代码,打印argvs:

this is my very simple code, printing argvs:

import sys

argv=sys.argv
for each in sys.argv:
    print each

这是运行时的输出:

e:\python>python test1.py 1 2 3 4 5
test1.py
1
2
3
4
5

我想编译它,所以我用py2exe做了一个:

I want it to be compiled, so I made one with py2exe:

e:\python>python setup.py py2exe

和我的 setup.py:

and my setup.py:

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
    options = {'py2exe': {'bundle_files': 3}},
    windows = [{'script': "test1.py"}],
    zipfile = None,
)

当我通过 test1.exe 1 2 3 4 5 或任何其他 argvs 运行我的程序时,我没有得到任何输出.sys.argvs 应该是一个列表,其中至少包含一个对象(test1.exe),因此我认为我对 python 的打印功能有误解.我在这里做错了什么吗?我只想将所有内容打印到命令行.我从 linux 编程,但 windows 用户应该使用我的程序.

and I don't get any output when I run my program by test1.exe 1 2 3 4 5 or with any other argvs. sys.argvs should be a list with at least one object(test1.exe) in it, therefore I think I have misunderstandings with print function of python. Is there anything I'm doing wrong here? I just want everything to be printed to commandline. I program from linux, but windows users should be using my program.

非常感谢

推荐答案

# ...
windows = [{'script': "test1.py"}],
#...

windows 选项用于创建 GUI 可执行文件,它会抑制控制台输出.使用 console 代替:

windows option is used to create GUI executables, which suppresses console output. Use console instead:

from distutils.core import setup
import py2exe, sys, os

sys.argv.append('py2exe')

setup(
    options = {'py2exe': {'bundle_files': 3}},
    console = [{'script': "test1.py"}],
    zipfile = None,
)

这篇关于使用 py2exe 编译时打印不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆