简体   繁体   English

如何在 Visual Studio Code 1.44.2 中打开交互式 shell/REPL?

[英]How do I open the interactive shell/REPL in Visual Studio Code 1.44.2?

I'm using Visual Studio Code, and I'd like to have a REPL that I can run single Python instructions in. I've found some year-old Microsoft documentation on this that says select the View > Other Windows > Interactive menu item, but there is no Other Windows item in my version of VS Code (1.44.2).我正在使用 Visual Studio Code,我想要一个 REPL,我可以在其中运行单个 Python 指令。我找到了一些年前的 Microsoft 文档,上面写着 select 视图 > 其他 ZAEA23428 交互菜单项9CE3AA9B64068CE3AA9B6406 ,但在我的 VS Code 版本(1.44.2)中没有其他 Windows 项目。

Does VS Code have a REPL feature, or do I have to run python.exe directly from the Terminal pane? VS Code 是否具有 REPL 功能,还是我必须直接从终端窗格运行 python.exe?

You are looking at the wrong documentation.您正在查看错误的文档。 That's for Visual Studio , not Visual Studio Code .这是针对Visual Studio的,而不是针对 Visual Studio Code的。 They are annoyingly similarly named, which can be confusing, but they are two completely different IDEs.它们的名称非常相似,令人讨厌,这可能会令人困惑,但它们是两个完全不同的 IDE。

The correct docs for VS Code is here: VS Code 的正确文档在这里:
https://code.visualstudio.com/docs/languages/python https://code.visualstudio.com/docs/languages/python

There is a section for running Python codes on the Terminal:终端上有一个运行 Python 代码的部分:
https://code.visualstudio.com/docs/languages/python#_run-python-code https://code.visualstudio.com/docs/languages/python#_run-python-code

I don't know about REPL, but you can use the standard Python console.我不了解 REPL,但您可以使用标准的 Python 控制台。

  1. Install the Python extension for VS Code 为 VS Code 安装 Python 扩展
  2. Setup and select the correct Python environment设置和select 正确的 Python 环境
    • Open the Command Palette then " Python: Select Interpreter "打开命令面板,然后“ Python: Select Interpreter 在此处输入图像描述
  3. Next, highlight the line you want to run, then right-click接下来,突出显示要运行的行,然后右键单击
  4. Select the Run Selection/Line in Python Terminal Select Python 终端中的运行选择/行在此处输入图像描述
  5. It should open up a Terminal panel and run your code in Python console它应该打开一个终端面板并在 Python 控制台中运行您的代码在此处输入图像描述
  6. You can then keep right-clicking > Run and it will execute on the same session然后您可以继续右键单击 > 运行,它将在相同的 session 上执行

There's also an option to run the entire file.还有一个选项可以运行整个文件。
See the Run Python Code section of the docs for more info.有关更多信息,请参阅文档的运行 Python 代码部分。

enter image description here u can open command pallete and type python:Start REPL在此处输入图像描述您可以打开命令托盘并输入python:Start REPL

this will open REPL这将打开 REPL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Visual Studio 代码交互式 window 中编辑单元格 - How do I edit a cell in visual studio code interactive window Visual Studio Code - 具有自动完成功能的 Python 交互式数据科学 REPL - Visual Studio Code - Python interactive data science REPL with autocomplete 如何在执行代码时打开或关闭Visual Studio python(Jupyter)交互式窗口(2019)? - How do i turn on or off the Visual Studio python (Jupyter) interactive window (2019) when executing code? 如何在 Visual Studio Code 中查找/执行 Python 交互模式? - How do I find/excute Python Interactive Mode in Visual Studio Code? Visual Studio 2017 中的 Python 3.6 如何在交互式 Shell 中运行程序 - Python 3.6 in Visual Studio 2017 How to Run Program in the Interactive Shell 如何测试在Python中使用input()和无限循环的REPL /交互式外壳 - How do you test a REPL/interactive shell that uses input() and infinite loop in python 如何在 Visual Studio 代码中打开 python 文件? - How do you open a python file in visual studio code? 如何在 Visual Studio Code 中打开 Hands.py 文件 - how do i open Hands.py file in Visual Studio Code 如何从Python打开Visual Studio代码? - How can I open visual studio code from Python? 我如何像在spyder中一样在visual studio中激活交互式python帮助 - how do I activate interactive python help in visual studio like in spyder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM