如何在 Visual Studio Code 的 launch.json 中调试 Python 模块 [英] How to debug a Python module in Visual Studio Code's launch.json

查看:115
本文介绍了如何在 Visual Studio Code 的 launch.json 中调试 Python 模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题可能看起来很简单,但是,我有一个在终端中启动的模块,如下所示:

My question may seem simple but, I have a module that I launch in a terminal like this:

python -m my_module.my_file

如何在 Visual Studio Code 中对此进行调试?

How do I debug this in Visual Studio Code?

我的 launch.json(文档)

"type": "python",
"request": "launch",
"pythonPath": "D:\\ProgramData\\Anaconda3\\envs\\simulec\\python.exe",
"args": [
   "-m",
   "my_module.my_file",
]

如果我没有设置 program 选项或者如果我将它设置为 "" 我得到文件不存在"错误.

If I don't set the program option or if I set it to "" I get "File does not exist" Error.

我该如何解决这个问题?

How can I fix this?

推荐答案

实际上,我在尝试编辑 launch.json 文件时偶然发现了一个非常简单的选项来执行此操作.

Actually, there is a very simple option to do this I found by accident while trying to edit the launch.json file.

"type": "python",
"request": "launch",
"pythonPath": "D:\\ProgramData\\Anaconda3\\envs\\simulec\\python.exe",
"module": "my_module.my_file",

只需在模块键module"中指定模块:my_module.my_file"

-m 不再有用.

这篇关于如何在 Visual Studio Code 的 launch.json 中调试 Python 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆