首页 > 解决方案 > 使用 pyinstaller 转换为 .exe 时,简单的打印语句在 python .py 中不起作用

问题描述

Python 文件包含一行打印语句

#file1.py
print("python to exe")

在windows环境下使用pyinstaller库成功将.py文件转换为.exe,得到可执行文件'file1.exe'

pyinstaller --onefile -w 'file1.py'

尝试在命令行提示符下执行“file1.exe” ,.exe 既不打印也不显示任何错误。任何帮助表示赞赏

标签: pythonprintingpyinstallerexe

解决方案


这是因为您使用的是“-w”选项。在 Windows 上,这将在运行程序时禁用控制台窗口。从 pyinstaller 文档中:

-w, --windowed, --noconsole

    Windows and Mac OS X: do not provide a console window for standard i/o. On Mac OS X this also triggers building an OS X .app bundle. On Windows this option will be set if the first script is a ‘.pyw’ file. This option is ignored in *NIX systems

推荐阅读