Print not working when compiled with py2exe

不羁的心 提交于 2020-01-13 08:43:11

问题


this is my very simple code, printing argvs:

import sys

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

here's the output when ran:

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

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

e:\python>python setup.py py2exe

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

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.

thank you very much


回答1:


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

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


来源:https://stackoverflow.com/questions/12505383/print-not-working-when-compiled-with-py2exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!