使用py2exe编译时,打印不起作用(Print not working when compiled with py2exe)

编程入门 行业动态 更新时间:2024-10-27 18:34:19
使用py2exe编译时,打印不起作用(Print not working when compiled with py2exe)

这是我非常简单的代码,打印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或其他任何argvs运行我的程序时,我没有得到任何输出。 sys.argvs应该是一个至少包含一个对象(test1.exe)的列表,因此我认为我对python的打印函数有误解。 有什么我在这里做错了吗? 我只想把一切都打印到命令行。 我从Linux编程,但Windows用户应该使用我的程序。

非常感谢你

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选项用于创建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, ) # ... 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, )

更多推荐

本文发布于:2023-07-24 13:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1246288.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   py2exe   Print   compiled   working

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!