简体   繁体   中英

Print not working when compiled with py2exe

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM