Tun*_*ata 2 python visual-studio-code vscode-settings
我需要帮助配置我的Vs代码以使用Cntrl Shift B在python中运行脚本,我工作正常,直到Vs代码升级到版本2.0.0,现在它要我配置Build.我无能为力Build是什么.
过去,当我只需要配置任务运行器时,它运行良好.任务运行器有youtube视频.我似乎无法确定Build的所有内容.
ora*_*Ink 13
在VS Code中,执行任务 - >配置任务
{
// 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
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
command:运行当前的python文件
group:'构建'
presentation:
第二个任务被配置为默认测试,只nosetest -v在VS Code中当前打开的文件夹中运行.
"运行构建任务"(绑定到Ctrl+ Shift+ B的那个)是配置为默认构建任务的那个,本例中的任务1(参见group条目).
编辑:
@RafaelZayas在评论中建议(这将使用在VS Code的设置中指定的Python解释器而不是系统默认值;有关更多信息,请参阅他的评论):
"command": "${config:python.pythonPath} ${file}"
小智 6
...没有足够的声誉来评论已接受的答案...
至少在我的环境(Ubuntu 18.04,带虚拟环境)中,如果使用“args”传入参数,则该文件必须是第一个参数,就像@VladBezden正在做的那样,而不是像@orangeInk正在做的命令的一部分。否则我会收到消息“没有这样的文件或目录”。
具体来说,@VladBezden 的答案对我有用,而以下答案则不起作用。
{
// 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
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
这花了我一段时间才弄清楚,所以我想我会分享。
| 归档时间: |
|
| 查看次数: |
6544 次 |
| 最近记录: |