简体   繁体   English

如何在 Visual Studio Code 中查找/执行 Python 交互模式?

[英]How do I find/excute Python Interactive Mode in Visual Studio Code?

I'm unable to find/execute the interactive mode in visual studio code - could you guys step-by-step me?我无法在 Visual Studio 代码中找到/执行交互模式 - 你们能一步一步地告诉我吗? Seems like a ridiculous question, I guess, but none of the waypoints I Googled seem to work;我想这似乎是一个荒谬的问题,但我在 Google 上搜索的所有航点似乎都不起作用;

I don't have "other windows"我没有“其他窗口”

If there's something I need to install, please let me know.如果有什么我需要安装的,请告诉我。

(Yes, I'm a beginner). (是的,我是初学者)。

In VSCode, you can enter the Python interactive window in the following places:在VSCode中,可以在以下几个地方进入Python交互窗口:

Option 1选项1

F1 -> Python: Create Python Interactive Window F1 -> Python:创建 Python 交互窗口

This is the Python interactive window that comes with VSCode.这是 VSCode 自带的Python 交互窗口。 You can enter the interactive window without inputting instructions.无需输入指令即可进入交互窗口。 Please use " Ctrl + Enter " to execute the code:请使用“ Ctrl + Enter ”执行代码:

option1_screenshot

Option 2选项 2

Ctrl + Shift + ` Ctrl + Shift + `

This is the cmd window that comes with the VSCode integration computer.这是VSCode集成电脑自带的cmd窗口。 We need to enter the command " python " to enter the Python interactive window:我们需要输入命令“ python ”才能进入Python交互窗口:

option2_screenshot

PS聚苯乙烯

For more information about using Python in Visual Studio Code , you can refer to the official VSCode documentation: Python in VSCode .关于在Visual Studio Code使用 Python 的更多信息,可以参考 VSCode 官方文档: Python in VSCode

If you have the Python extension, you can use the Python Interactive feature (this is a IPython/Jupyter console, which can run parts of your code as 'cells', ie snippets of code executed in one go).如果您有 Python 扩展,您可以使用 Python 交互功能(这是一个 IPython/Jupyter 控制台,它可以将您的部分代码作为“单元”运行,即一次性执行的代码片段)。

This article writes about the interactive window and many more possibilities of using Jupyter in VS Code: https://code.visualstudio.com/docs/python/jupyter-support-py本文介绍了交互式窗口以及在 VS Code 中使用 Jupyter 的更多可能性: https ://code.visualstudio.com/docs/python/jupyter-support-py

Best option最佳选择

When editing Python code, select something and press Shift + Enter .编辑 Python 代码时,选择某些内容并按Shift + Enter This will open the interactive window and run your selection as a single cell.这将打开交互式窗口并将您的选择作为单个单元格运行。

I have personally been annoyed many times by accidentally pressing Shift + Enter instead of Enter on a line of code which (alone) would be a syntax error.我个人被意外按下惹恼了很多次Shift + Enter ,而不是Enter的一行代码,其(单独)将是一个语法错误。 Then, one day I decided to start using this feature consciously.然后,有一天我决定开始有意识地使用这个功能。

Terminal fallback终端回退

Press:按:

Ctrl+`

This opens a system shell (bash, or on Windows: Powershell or cmd).这将打开一个系统外壳(bash,或在 Windows 上:Powershell 或 cmd)。 Run python , or ipython if you have it ( pip install ipython ), and use the interactive window.运行pythonipython如果有)( pip install ipython ),并使用交互式窗口。 In the terminal, you can also execute your script, by typing python myscript.py arguments .在终端中,您还可以通过键入python myscript.py arguments来执行脚本。

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

相关问题 如何在交互模式下在Visual Studio Code中运行我的Python模块? - How to run my Python module in Visual Studio Code in interactive mode? 如何在 Visual Studio 代码交互式 window 中编辑单元格 - How do I edit a cell in visual studio code interactive window 如何在执行代码时打开或关闭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 1.44.2 中打开交互式 shell/REPL? - How do I open the interactive shell/REPL in Visual Studio Code 1.44.2? 我如何像在spyder中一样在visual studio中激活交互式python帮助 - how do I activate interactive python help in visual studio like in spyder Visual Studio代码交互式python控制台 - Visual studio code interactive python console 在 Python 中,如何使用交互式命令行(和可视断点?)进行调试 - In Python, how do I debug with an interactive command line (and visual breakpoints?) 如何在 vs 代码中禁用 python 交互模式? - How to disable python interactive mode in vs code? Visual Studio Code - 具有自动完成功能的 Python 交互式数据科学 REPL - Visual Studio Code - Python interactive data science REPL with autocomplete Visual Studio Code Python Interactive Window env 与所选不同? - Visual Studio Code Python Interactive Window env different from selected?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM