简体   繁体   English

无法让 VS Code 从 launch.json 传递 arguments 到 Python

[英]Cannot get VS Code to pass arguments to Python from launch.json

I cannot figure out how to get VS Code for Mac to start debugging my Python script with the arguments I have defined in my launch.json file by using the debug button to the right I have circled here.我不知道如何让 VS Code for Mac 开始使用我在 launch.json 文件中定义的 arguments 调试我的 Python 脚本,方法是使用我在此处圈出的右侧调试按钮。 The only way I can get my arguments to be recognized is if I go to the menu and select "Run|Start Debugging" or if press F5.让我的 arguments 被识别的唯一方法是如果我 go 到菜单和 select “运行|开始调试”或者按 F5。

How do I tell VS Code to use my launch.json file when using that button???使用该按钮时如何告诉 VS Code 使用我的 launch.json 文件???

If you look at the answer from Sourya Dey at the link below, this is what made me write this.如果您在下面的链接中查看 Sourya Dey 的回答,这就是我写这篇文章的原因。 There must be some simple setting or step missing to link that button to F5.必须缺少一些简单的设置或步骤才能将该按钮链接到 F5。 It appears others are also confused about this.看来其他人也对此感到困惑。

Visual Studio Code: How debug Python script with arguments Visual Studio Code:如何使用 arguments 调试 Python 脚本

适用于 Mac 的 VS 代码

For clarity, here is my launch.json file which works as expected with F5.为清楚起见,这是我的 launch.json 文件,它按预期与 F5 一起工作。 It does not work with the button I have circled in red above它不适用于我在上面用红色圈出的按钮

启动.json

In your Python code, you can call debugpy.breakpoint() at any point where you want to pause the debugger during a debugging session.在您的 Python 代码中,您可以在调试 session 期间要暂停调试器的任何位置调用debugpy.breakpoint() I recommend reading this document for more information.我建议阅读此文档以获取更多信息。 You can also add a manual breakpoint by clicking the left part of the line numbers shown on the side of the source code window.您还可以通过单击源代码 window 侧面显示的行号的左侧来添加手动断点。 When the program stops at the breakpoint during debug, you can see the current value of the variable when you move the cursor over the variable.当程序在调试过程中停在断点处时,将 cursor 移到变量上时可以看到变量的当前值。

To debug Python code in VS Code, install the following plugins:要在 VS Code 中调试 Python 代码,请安装以下插件:

在此处输入图像描述

I filed a bug with the Microsoft VS Code team regarding this issue and they sent me over to the Microsoft Python extension group.我向 Microsoft VS Code 团队提交了有关此问题的错误,他们将我发送到 Microsoft Python 扩展组。 I then filed a bug there referencing the VC Code ticket and it was immediately assigned for "area-debugging triage".然后我在那里提交了一个引用 VC 代码票证的错误,并立即将其分配给“区域调试分类”。 I presume this will be fixed in a later version (I am on 1.63.2)我想这将在以后的版本中修复(我在 1.63.2 上)

First, it is not obvious where this button comes from.首先,这个按钮的来源并不明显。 I have noted this issue as well with Microsoft so they can improve their documentation.我也向 Microsoft 指出了这个问题,因此他们可以改进他们的文档。 When you install VS Code with no extensions, this button is not present.当您安装没有扩展的 VS Code 时,此按钮不存在。 But as soon as you load your first Python file, Microsoft urges you to install the official "Microsoft Python Extension" and then the button shows up.但是,一旦您加载了第一个 Python 文件,Microsoft 就会敦促您安装官方的“Microsoft Python Extension”,然后按钮就会出现。 In my mind, I assumed this was a native VS Code button that showed up when you had a language debugger installed.在我看来,我认为这是一个原生的 VS Code 按钮,当你安装了语言调试器时就会出现。 When I removed all extensions, except the Microsoft Python extension, I was convinced this was part of VS Code.当我删除除 Microsoft Python 扩展之外的所有扩展时,我确信这是 VS Code 的一部分。

The answer above incorrectly states that this is the correct behaviour for the button.上面的答案错误地指出这是按钮的正确行为。 It is not.它不是。 Microsoft has confirmed this and if you read issue #2338 ("Documentation for python.terminal.launchArgs is unclear") there is a response in there stating: Microsoft 已经确认了这一点,如果您阅读了问题 #2338(“python.terminal.launchArgs 的文档不清楚”),那里会有回复说明:

"Unfortunately that's just how vscode works. When debugging all settings are read from launch.json and non-debugging settings.json is used This applies to all languages (extensions) in vscode." “不幸的是,这就是 vscode 的工作方式。调试时,所有设置都是从启动中读取的。json 和非调试设置。使用 json 这适用于 vscode 中的所有语言(扩展)。”

So for now, there is nothing much to do other than wait for this to be fixed.所以现在,除了等待这个问题得到修复之外,没有什么可做的。

Lastly, for those who are wondering why I wanted to use that button in the first place.最后,对于那些想知道我为什么要首先使用该按钮的人。 For the most part, I use keyboard mappings to start debugging when I am inside VS Code.大多数情况下,当我在 VS Code 中时,我会使用键盘映射来开始调试。 But for this particular project, I was going to other external windows and when coming back to VS Code, since I was already using the mouse, I just wanted to click there out of convenience.但是对于这个特定的项目,我要去其他外部 windows 并且当回到 VS Code 时,由于我已经在使用鼠标,我只是想点击那里方便。 I don't keep the debug tab open which also has a debug button that works as intended.我没有打开调试选项卡,它也有一个按预期工作的调试按钮。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过 launch.json 在 VS 代码中将参数传递给 python 解释器(而不是 python 代码) - How to pass an argument to the python interpreter (not to the python code) in VS code via launch.json VS Code将launch.json转化为实际命令 - VS Code launch.json into an actual command python 程序无法从 VSCode 的 launch.json 获取参数? - python program can not get the args from the launch.json of VSCode? 在 VS Code 中,我根本无法在 launch.json 中运行命令行 arguments。 我究竟做错了什么? - In VS Code I just can't get command line arguments in launch.json working at all. What am I doing wrong? 如何在 VS 代码中配置 launch.json 以在 Windows 中接受网络路径(python) - how to configure the launch.json in VS code to accept a network path (python) in windows vscode python调试,launch.json中带有参数语法错误 - vscode python debug with arguments syntax error in launch.json VS Code:如何在launch.json中通过shell命令获取进程ID? - VS Code: how to get process ID via shell command in launch.json? Visual Studio Code launch.json 设置用于调试 Python 模块 - Visual Studio Code launch.json settings for debugging Python modules 在 Visual Studio Code 中为文件“launch.json”设置 Python 路径 - Setting the Python path in Visual Studio Code for file 'launch.json' 在 VS Code 中,当通过调试器运行 python 程序时,在 launch.json 中设置了 internalConsole,然后我无法从命令行接收输入 - In VS Code, when running a python program via the debugger, with internalConsole set in launch.json, then I can't receive input from the command line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM