【问题标题】:Print not working when compiled with py2exe使用 py2exe 编译时打印不起作用
【发布时间】:2012-09-20 02:33:36
【问题描述】:

这是我非常简单的代码,打印 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做了一个:

e:\python>python setup.py py2exe

还有我的 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 或任何其他 argv 运行我的程序时,我没有得到任何输出。 sys.argvs 应该是一个包含至少一个对象(test1.exe)的列表,因此我认为我对 python 的打印功能有误解。 我在这里做错了什么吗?我只想将所有内容都打印到命令行。我从 linux 编程,但 windows 用户应该使用我的程序。

非常感谢

【问题讨论】:

    标签: python printing py2exe


    【解决方案1】:
    # ...
    windows = [{'script': "test1.py"}],
    #...
    

    windows 选项用于创建 GUI 可执行文件,从而抑制控制台输出。请改用console:

    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,
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-04
      • 1970-01-01
      • 2013-10-24
      • 1970-01-01
      • 2018-04-26
      • 2014-05-02
      • 2011-02-23
      • 1970-01-01
      相关资源
      最近更新 更多