cx_Freeze不打印到控制台 [英] cx_Freeze doesn't print to console
问题描述
我有一个应用程序,可以在运行时将一些内容打印到控制台。但是作为一个独立的可执行文件,它不会在控制台上打印任何内容吗?
I have an application that prints a few things to the console upon running. But as a standalone the executable doesn't print anything to the console?
setup.py脚本如下:
The setup.py script looks like this:
import sys
from cx_Freeze import setup, Executable
setup(
name = "My App",
version = "1.0",
options = {
"build_exe" : {
"include_files": ['MyImgs']
},
},
executables = [Executable("Main.py", base = "Win32GUI")]
)
在命令行中运行以下命令: py setup.py build
On the command line I run the following: py setup.py build
然后我找到可执行文件并运行: Main.exe
。
I then find the executable and run: Main.exe
.
由于某种原因,我缺少了任何 print()
语句。
What I am missing for some reason is any print()
statements. Is there something I need to include in the setup script for this to happen?
推荐答案
如果您使用 Win32GUI库,是否需要在安装脚本中添加一些内容? Windows将无法使用stdout和stderr。您将需要将自己重定向到其他位置(例如文件)。如果您使用 Console基础,则可以使用stdout和stderr,并且print()可以按预期工作-但是,如果您首先没有从控制台运行它,就会看到为您创建的控制台!
If you use the "Win32GUI" base, then Windows does not make available stdout and stderr. You will need to redirect those yourself to some other location (such as a file). If you use the "Console" base then stdout and stderr are available and print() will work as expected -- but you will see a console created for you if you haven't run it from a console in the first place!
这篇关于cx_Freeze不打印到控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!