Visual Studio Code最近发布了,我喜欢它的外观和提供的功能,所以我想尝试一下。
我从下载页面下载了应用程序,启动了它,对一些功能做了一些调整……然后意识到我不知道如何实际执行我的任何Python代码!
我真的很喜欢Visual Studio代码的外观和感觉/可用性/特性,但我似乎不知道如何运行我的Python代码,这是一个真正的杀手,因为我主要用Python编程。
是否有一种方法可以在Visual Studio code中执行Python代码?
Visual Studio Code最近发布了,我喜欢它的外观和提供的功能,所以我想尝试一下。
我从下载页面下载了应用程序,启动了它,对一些功能做了一些调整……然后意识到我不知道如何实际执行我的任何Python代码!
我真的很喜欢Visual Studio代码的外观和感觉/可用性/特性,但我似乎不知道如何运行我的Python代码,这是一个真正的杀手,因为我主要用Python编程。
是否有一种方法可以在Visual Studio code中执行Python代码?
当前回答
简单直接的Python扩展可以节省时间和精力。 检测、调试、代码完成是安装完成后可用的特性。在此之后,要运行代码,需要配置正确的Python安装路径以运行代码。一般设置可在“用户作用域”和“工作空间”中为Python语言-“Python”配置。pythonPath环境”:“c: / python27 / python.exe” 通过以上步骤,至少可以执行基本的Python程序。
其他回答
您可以添加一个自定义任务来完成此任务。下面是Python的一个基本自定义任务。
{
"version": "0.1.0",
"command": "c:\\Python34\\python",
"args": ["app.py"],
"problemMatcher": {
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*)+s$",
"message": 1
}
}
}
将其添加到文件任务中。并按Ctrl + Shift + B运行它。
有一个最简单的方法来创建run in terminal命令的快捷方式:
点击左边栏上的设置图标。 然后点击键盘快捷键。 粘贴python。execInTerminal在搜索栏顶部。 现在双击Python: Run Python File in Terminal命令对面的Keybinding列并设置快捷方式。
一个解决办法是:
选择所有的行:按Ctrl + A 运行选定的行:Shift + Enter
正如Visual Studio Code文档中所述,只需右键单击编辑器中的任何位置,并选择在终端中运行Python文件。
注意:你必须在Visual Studio Code中安装Python Extension By Microsoft,并在左下角选择Python解释器。
Go to File → Preferences → Keyboard Shortcuts (alternatively, you can press Ctrl + K + S) In the search box, enter python.execInTerminal Double click that result (alternatively, you can click the plus icon) Press Ctrl + Alt + B to register this as the keybinding (alternatively, you can enter your own keybinding) Now you can close the Keyboard Shortcuts tab Go to the Python file you want to run and press Ctrl + Alt + B (alternatively, you can press the keybinding you set) to run it. The output will be shown in the bottom terminal tab.