2024-05-13 03:12:47 发布
网友
我需要帮助配置我的Vs代码,以便使用Cntrl Shift B在python中运行脚本,在Vs代码升级到版本2.0.0之前,我一直工作得很好,现在它希望我配置构建。我不知道建筑是什么。
在过去,当我只需要配置任务运行器时,它工作得很好。有任务执行者的youtube视频。我似乎无法确定这座建筑到底是怎么回事。
这是我的构建配置(Ctrl+Shift+B)
{ // 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 } } ] }
…没有足够的声誉来评论接受的答案。。。
至少在我的环境(Ubuntu 18.04,w/virtual env)中,如果参数是用“args”传入的,那么文件必须是第一个参数,就像@VladBezden所做的,而不是@orangeInk所做的命令的一部分。否则我会收到消息“没有这样的文件或目录”。
具体来说,@VladBezden has的答案确实对我有效,而下面的答案确实对我有效。
{ // 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 } } ] }
我花了一段时间才弄明白,所以我想我会分享。
在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 } } ] }
command:运行当前的python文件
command
group:“构建”
group
presentation:
presentation
第二个任务被配置为默认测试,只在VS代码中当前打开的文件夹中运行nosetest -v。
nosetest -v
“运行生成任务”(绑定到Ctrl+Shift+B)的任务是配置为默认生成任务的任务1(请参见本例中的group条目)。
Ctrl
Shift
B
编辑: 由@RafaelZayas在注释中建议(这将使用VS Code设置中指定的Python解释器,而不是系统默认解释器;有关更多信息,请参阅他的注释):
"command": "${config:python.pythonPath} ${file}"
这是我的构建配置(Ctrl+Shift+B)
tasks.json
…没有足够的声誉来评论接受的答案。。。
至少在我的环境(Ubuntu 18.04,w/virtual env)中,如果参数是用“args”传入的,那么文件必须是第一个参数,就像@VladBezden所做的,而不是@orangeInk所做的命令的一部分。否则我会收到消息“没有这样的文件或目录”。
具体来说,@VladBezden has的答案确实对我有效,而下面的答案确实对我有效。
我花了一段时间才弄明白,所以我想我会分享。
在VS代码中执行任务->;配置任务
command
:运行当前的python文件group
:“构建”presentation
:第二个任务被配置为默认测试,只在VS代码中当前打开的文件夹中运行
nosetest -v
。“运行生成任务”(绑定到
Ctrl
+Shift
+B
)的任务是配置为默认生成任务的任务1(请参见本例中的group
条目)。编辑:
由@RafaelZayas在注释中建议(这将使用VS Code设置中指定的Python解释器,而不是系统默认解释器;有关更多信息,请参阅他的注释):
"command": "${config:python.pythonPath} ${file}"
相关问题 更多 >
编程相关推荐