为python配置Vs代码版本2.0.0构建任务
我需要帮助来配置我的Vs代码以使用Cntrl Shift B在python中运行脚本,在Vs代码升级到2.0.0版本之前,我一直工作正常,现在它希望我配置构建。我不知道建造是关于什么的为python配置Vs代码版本2.0.0构建任务,python,visual-studio-code,vscode-settings,Python,Visual Studio Code,Vscode Settings,我需要帮助来配置我的Vs代码以使用Cntrl Shift B在python中运行脚本,在Vs代码升级到2.0.0版本之前,我一直工作正常,现在它希望我配置构建。我不知道建造是关于什么的 在过去,当我只需要配置任务运行器时,它工作得很好。有任务运行者的youtube视频。我似乎无法确定这座建筑到底是什么 在VS代码执行任务->配置任务中 { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the docume
在过去,当我只需要配置任务运行器时,它工作得很好。有任务运行者的youtube视频。我似乎无法确定这座建筑到底是什么 在VS代码执行任务->配置任务中
{
// 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
}
}
]
}
命令
:运行当前python文件
组
:“构建”
演示文稿
:
- 运行时始终显示外壳
- 使用新外壳
- 聚焦外壳(即在外壳窗口中捕获键盘)
nosetest-v
“运行构建任务”(绑定到Ctrl
+Shift
+B
)是配置为默认构建任务的任务(本例中为任务1)(请参见组
条目)
编辑:由@RafaelZayas在注释中建议(这将使用VS代码设置中指定的Python解释器,而不是系统默认值;有关更多信息,请参阅他的注释):
“command”:“${config:python.pythonPath}${file}”
以下是我的构建配置(Ctrl+Shift+B)
tasks.json
…没有足够的声誉来评论公认的答案 至少在我的环境(Ubuntu18.04,w/virtual env)中,如果参数是用“args”传入的,那么文件必须是第一个参数,就像@VladBezden所做的那样,而不是@orangeInk所做的命令的一部分。否则我会收到消息“没有这样的文件或目录” 具体来说,@VladBezden has的答案对我来说确实有效,而下面的答案则不适用
我花了一段时间才弄明白,所以我想与大家分享。我试过你的代码,但执行任务时出现错误
>执行任务:python d:\books\programming Languages\python\Projects\.vscode\tasks.json
我可以推荐:“command”:“${config:python.pythonPath}${file}”`用config变量替换python将使用与python VS代码扩展中设置的pythonPath相同的pythonPath。如果在windows上,则将使用cmd.exe或PowerShell运行。根据具体情况(我认为PowerShell适用于Win 10或更高版本),在$file变量周围加上一个单引号或双引号,即“command”:“${config:python.pythonPath}”${file}”非常棒的配置,非常有用。只是想补充一点,他们最近将taskName
更改为label
,这不是什么大事,只是VS代码中的警告。
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "python",
"group": {
"kind": "build",
"isDefault": true
},
"args": [
"setup.py",
"install"
],
"presentation": {
"echo": true,
"panel": "shared",
"focus": true
}
}
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "${config:python.pythonPath} setup.py", // WRONG, move setup.py to args
"group": {
"kind": "build",
"isDefault": true
},
"args": [
"install"
],
"presentation": {
"echo": true,
"panel": "shared",
"focus": true
}
}
]
}