How to debug a Python module in Visual Studio Codes launch.json

2024/11/19 19:44:27

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

python -m my_module.my_file

How do I debug this in Visual Studio Code?

I have this in my launch.json (documentation)

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

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?

Answer

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",

Simply specify the module in the module key "module": "my_module.my_file"

The -m is not useful any more.

https://en.xdnf.cn/q/26408.html

Related Q&A

Cleanest Fastest server setup for Django [closed]

Closed. This question is opinion-based. It is not currently accepting answers.Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.Clo…

Quicker to os.walk or glob?

Im messing around with file lookups in python on a large hard disk. Ive been looking at os.walk and glob. I usually use os.walk as I find it much neater and seems to be quicker (for usual size direct…

Getting PyCharm to recognize python on the windows linux subsystem (bash on windows)

While running Linux versions of python, pip etc. "natively" on windows is amazing, Id like to do so using a proper IDE. Since SSHD compatibility has not been implemented yet, Im trying get Py…

Whats the difference between nan, NaN and NAN

In numpy there are nan, NaN and NAN. Whats the sense of having all three, do they differ or any of these can be used interchangeably?

Python requests: URL base in Session

When using a Session, it seems you need to provide the full URL each time, e.g.session = requests.Session() session.get(http://myserver/getstuff) session.get(http://myserver/getstuff2)This gets a littl…

size of NumPy array

Is there an equivalent to the MATLAB size() command in Numpy? In MATLAB, >>> a = zeros(2,5)0 0 0 0 00 0 0 0 0 >>> size(a)2 5In Python, >>> a = zeros((2,5)) >>> a ar…

Feature Importance Chart in neural network using Keras in Python

I am using python(3.6) anaconda (64 bit) spyder (3.1.2). I already set a neural network model using keras (2.0.6) for a regression problem(one response, 10 variables). I was wondering how can I generat…

numpy.max or max ? Which one is faster?

In python, which one is faster ? numpy.max(), numpy.min()ormax(), min()My list/array length varies from 2 to 600. Which one should I use to save some run time ?

Nested Json to pandas DataFrame with specific format

I need to format the contents of a Json file in a certain format in a pandas DataFrame so that I can run pandassql to transform the data and run it through a scoring model. file = C:\scoring_model\json…

Iterating over dictionary items(), values(), keys() in Python 3

If I understand correctly, in Python 2, iter(d.keys()) was the same as d.iterkeys(). But now, d.keys() is a view, which is in between the list and the iterator. Whats the difference between a view and …