Question:
Can I use VS Code's launch config to run a specific python file?

Problem:


In my Python project I have a module my_stuff.py which is active in my editor, but I want to execute the file main.py to run my project. -- Can I use launch.json for this?


I tried a simple config like this:

{

    // Use IntelliSense to learn about possible attributes.

    // Hover to view descriptions of existing attributes.

    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387

    "version": "0.2.0",

    "configurations": [

        {

            "name": "Python: Main File",

            "type": "python",

            "request": "launch",

            "program": "main.py",

            "console": "integratedTerminal",

            "justMyCode": true

        },

    ]

}


But this always wants to start the debugpy launcher. I would just like to launch the main file as

/my/venv/python /my/project/dir/main.py

How can I do this with launch.json?


Solution:

Now you can configure >program in launch.json and then use Ctrl+F5 (Run Without Debugging)to execute the program. But essentially this still uses the debugger.



There was a feature request to configure the Run button, but it was closed due to insufficient votes.

There is also a related request open.

There is also a related SO question.


Suggested blogs:

>How to migrate `DateTimeField` to `DateField` in Django?

>Why VSCode indicate an error on using {{ }}?

>Fix the python-decouple issue in Django

>Address the N+1 problem in Django with prefetch

>How can I retrieve all customers' bookings by their username/ID?

>How to solve Static Files not being found in Django?

>How to format date-time input in Django?



Ritu Singh

Ritu Singh

Submit
0 Answers