Home > Mobile >  How to run a python file as a module with the "Run Python File" button in VS Code?
How to run a python file as a module with the "Run Python File" button in VS Code?

Time:01-26

I have Visual Studio Code 1.74.3 with the Microsoft Python extension v2022.20.2.

I am talking about the button to run a python file and specifically not about run/debug configurations or tasks.

enter image description here

Per default this button seems to use the configured python interpreter and runs: python.exe filename.py.

However, I want to run files as a module: python.exe -m filename

Is that possible somehow?

I found the setting "python.terminal.launchArgs" to add the "-m", but then there is still the problem that just the filename is required without the ".py" extension.

CodePudding user response:

You can do that with the python debugger. There it is possible to add specific launch configurations. When creating the launch.json file, select python module.
I'm not sure if you can start it without the debugger attached.

enter image description here

This is the execution effect:

enter image description here

  • Related