将输出从集成终端VSCode更改为Windows cmd提示符

时间:2019-10-29 16:28:23

标签: python visual-studio-code

我有一个python脚本,可以自动完成一些excel工作。我目前正在使用VSCode。

我已经安装了PyInstaller并创建了一个.exe文件来运行脚本。

我想打开Windows cmd提示符并打印completed等。

当我从VSCode运行它时,它会输出到集成终端-没问题。从.exe文件没有任何显示...

我希望有一种方法可以打开一个单独的窗口(没有集成的窗口),并在有人可以直接指向我的地方打印一些文本。

1 个答案:

答案 0 :(得分:0)

在为脚本运行pyinstaller时,可以使用--console-c选项。更多信息here

这使您可以显示控制台窗口,并且可以在脚本中使用print语句。

示例:

pyinstaller --console myscript.py

如果您已经构建了.exe,则可以更新.spec文件。

您需要将console=True参数添加到EXE方法中,例如:

exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='main',
          debug=False,
          strip=False,
          console=True)

然后运行:

pyinstaller your_script.spec

相关链接:

https://www.reddit.com/r/learnpython/comments/6b8s7c/will_the_effects_of_print_statements_be_visible/

Getting rid of console output when freezing Python programs using Pyinstaller

https://github.com/chriskiehl/Gooey/issues/235