最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to make Visual Studio 2022 Python CLI project launch Windows Terminal instead of Python.exe? - Stack Overflow

programmeradmin1浏览0评论

This is a Windows 11 machine. I have 2 projects in a Visual Studio 2022 solution.

  1. A Python CLI.
    When I run this app, it opens the python.exe terminal.

  1. A C# Console app.
    When I run this app, I think it opens cmd.exe terminal.

For the Python app also, I would like to run it in Windows cmd.exe terminal, so that I can use text formatters like colorama or termcolor.
The Environment is already set for cmd.exe, but it doesn't seem to work.

So, is it possible to run the Python CLI app, from VS 2022, in a Windows CMD terminal.

This is a Windows 11 machine. I have 2 projects in a Visual Studio 2022 solution.

  1. A Python CLI.
    When I run this app, it opens the python.exe terminal.

  1. A C# Console app.
    When I run this app, I think it opens cmd.exe terminal.

For the Python app also, I would like to run it in Windows cmd.exe terminal, so that I can use text formatters like colorama or termcolor.
The Environment is already set for cmd.exe, but it doesn't seem to work.

So, is it possible to run the Python CLI app, from VS 2022, in a Windows CMD terminal.

Share Improve this question edited Mar 24 at 16:02 President James K. Polk 42.1k29 gold badges109 silver badges145 bronze badges asked Mar 19 at 10:19 sukeshsukesh 2,41112 gold badges64 silver badges130 bronze badges 9
  • Visual Studio is likely running Python scripts using python.exe directly, which may prevent ANSI escape sequences (used by printy and colorama) from rendering correctly. This happens because python.exe does not enable ANSI support by default unless run inside a proper terminal like cmd.exe, PowerShell, or Windows Terminal. – user23633404 Commented Mar 19 at 10:45
  • What do you see when you got to Options then Python then Interactive Window? Does it show CMD in the script text box? – user23633404 Commented Mar 19 at 12:13
  • It has an option to select an Environment, and another for "Module". In the Environment, the current project's env is selected, and in the Module, "main" is preselected. There is no other place when I can select a terminal. – sukesh Commented Mar 19 at 12:27
  • That box under Interactive Windows should be empty – user23633404 Commented Mar 19 at 12:42
  • 1 Uninstalling and re installing the python development workload may work since the existing configuration that is using python.exe to run the code will be deleted, allowing for the new installation to create a configuration that may produce the results you intend to achieve. – user23633404 Commented Mar 20 at 5:01
 |  Show 4 more comments

1 Answer 1

Reset to default 0

1: Open the Integrated Terminal:

You can go to "View" and select "Terminal" to open an integrated terminal. Since your terminal setting already has cmd.exe as the default shell, the terminal will use that.

2: Run your Python Script:

Inside the integrated terminal, you can navigate to your directory using cd and run your Python file. python your_filename.py

This method will help you to run your Python Script inside cmd.exe, so that libraries like colorama or termcolor can format text effectively.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论