Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 496
thkang Avatar asked Sep 20 '12 02:09

thkang


1 Answers

# ...
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,
)
like image 122
Avaris Avatar answered Sep 17 '22 15:09

Avaris