为python配置Vs code version 2.0.0 Build Task [英] Configure Vs code version 2.0.0 Build Task for python
问题描述
我需要帮助来配置我的 Vs 代码以使用 Cntrl Shift B 在 python 中运行脚本,我一直工作正常,直到 Vs 代码升级到版本 2.0.0 现在它想让我配置 Build.而且我对 Build 的全部内容一无所知.
I need help in configuring my Vs code to run scripts in python using Cntrl Shift B, I was working fine until Vs code upgraded to version 2.0.0 now it wants me to configure the Build. And I am clueless what Build is all about.
过去,当我只需要配置任务运行器时,它运行良好.有任务运行程序的 youtube 视频.我似乎无法弄清楚 Build 的全部内容.
In the past it worked well when I only needed to configure the task runner. There are youtube videos for the task runner. I cant seem to lay my finger on what the Build is all about.
推荐答案
在 VS Code 中 go Tasks -> Configure Tasks
In VS Code go Tasks -> Configure Tasks
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "Run File",
"command": "python ${file}",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new",
"focus": true
}
},
{
"taskName": "nosetest",
"command": "nosetests -v",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new",
"focus": true
}
}
]
}
command
:运行当前python文件
command
: runs current python file
group
: 'build'
演示
:
- 运行时总是显示shell
- 使用新的外壳
- 聚焦外壳(即在外壳窗口中捕获键盘)
第二个任务被配置为默认测试,并且只在当前在 VS Code 中打开的文件夹中运行 nosetest -v
.
2nd Task is configured as the default test and just runs nosetest -v
in the folder that's currently open in VS Code.
运行构建任务"(绑定到 Ctrl
+Shift
+B
的那个)是被配置为默认的那个构建任务,本例中的任务 1(请参阅 group
条目).
The "Run Build Task" (the one that's bound to Ctrl
+Shift
+B
) is the one that's configured as the default build task, task 1 in this example (see the group
entry).
@RafaelZayas 在评论中建议(这将使用在 VS Code 设置中指定的 Python 解释器而不是系统默认值;有关更多信息,请参阅他的评论):
Suggested by @RafaelZayas in the comments (this will use the Python interpreter that's specified in VS Code's settings rather than the system default; see his comment for more info):
"command": "${config:python.pythonPath} ${file}"
这篇关于为python配置Vs code version 2.0.0 Build Task的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!