python程序中的.pyw文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34739315/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 15:26:44  来源:igfitidea点击:

.pyw files in python program

pythonpython-3.x

提问by Arnb

I am new to Python programming. Can anybody provide an explanation on what a *.pyw file is and how it works.

我是 Python 编程的新手。任何人都可以解释什么是 *.pyw 文件以及它是如何工作的。

采纳答案by absolutelyNoWarranty

Python scripts (files with the extension .py) will be executed by python.exeby default. This executable opens a terminal, which stays open even if the program uses a GUI. If you do not want this to happen, use the extension .pyw which will cause the script to be executed by pythonw.exeby default (both executables are located in the top-level of your Python installation directory). This suppresses the terminal window on startup.

You can also make all .py scripts execute with pythonw.exe, setting this through the usual facilities, for example (might require administrative rights):

默认情况下,Python 脚本(扩展名为 .py 的文件)将由python.exe执行 。此可执行文件会打开一个终端,即使程序使用 GUI,该终端也会保持打开状态。如果您不希望发生这种情况,请使用扩展名 .pyw,这将导致脚本默认由pythonw.exe执行(两个可执行文件都位于 Python 安装目录的顶层)。这会在启动时抑制终端窗口。

您还可以使用 pythonw.exe 执行所有 .py 脚本,例如通过常用工具进行设置(可能需要管理权限):

https://docs.python.org/2/using/windows.html

https://docs.python.org/2/using/windows.html

So in practice the only difference is that one leaves a console window hanging around and the other doesn't. The most obvious usage for *.pyw are GUI apps since an app with an independent GUI obviously does not need or want the console window around.

所以在实践中唯一的区别是一个控制台窗口挂在周围,另一个没有。*.pyw 最明显的用法是 GUI 应用程序,因为具有独立 GUI 的应用程序显然不需要或不需要控制台窗口。

There are some subtle implementation differences between python.exe and pythonw.exe see https://stackoverflow.com/a/30313091/3703989

python.exe 和 pythonw.exe 之间存在一些细微的实现差异,请参见https://stackoverflow.com/a/30313091/3703989

回答by Manikandan k

The PYW file type is primarily associated with Python by Python Software Foundation. PYW files are used in Windows to indicate a script needs to be run using PYTHONW. EXE instead of PYTHON. EXE in order to prevent a DOS console from popping up to display the output.

PYW 文件类型主要由 Python Software Foundation 与 Python 相关联。PYW 文件在 Windows 中用于指示需要使用 PYTHONW 运行的脚本。EXE 而不是 PYTHON。EXE 以防止弹出 DOS 控制台以显示输出。