Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Python Main RunnerNew to Visual Studio Code? Get it now.
Python Main Runner

Python Main Runner

Kirby

|
2 installs
| (0) | Free
Run any Python file containing if __name__ == "__main__" from a convenient launcher.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Python Main Runner

A Visual Studio Code extension that makes it easier to run Python projects with multiple entry points.

Python projects often contain multiple files with:

if __name__ == "__main__":

However, VS Code's default Run Python File button only runs the currently opened file.

Python Main Runner scans your workspace for Python entry points and allows you to quickly select and run any of them without opening the file first.


Features

  • 🔍 Automatically detects Python entry points
  • ▶ Run any Python file containing if __name__ == "__main__"
  • 📂 Supports nested folders
  • 💾 Remembers your selected entry point
  • 🔄 Automatically rescans when Python files are created, changed, or deleted
  • 🖥 Runs selected files in a dedicated VS Code terminal
  • 🚫 Ignores common virtual/environment folders:
    • .git
    • node_modules
    • __pycache__
    • venv
    • .venv

Example

Given this project:

my-project/
│
├── src/
│   ├── main.py
│   └── server.py
│
├── tools/
│   └── migrate.py
│
└── README.md

With:

src/main.py

if __name__ == "__main__":
    print("Application started")

src/server.py

if __name__ == "__main__":
    print("Server started")

tools/migrate.py

if __name__ == "__main__":
    print("Migration started")

Python Main Runner detects:

src/main.py
src/server.py
tools/migrate.py

You can then select any of them and run them directly from VS Code.


Usage

  1. Open a Python project folder in VS Code.
  2. Python Main Runner automatically searches for entry points.
  3. Use the Python Main Runner toolbar button.
  4. Select the Python entry point you want to use.
  5. Press the run button to execute it.

The selected entry point is saved and restored when reopening the project.


Requirements

  • Visual Studio Code 1.125.0 or newer
  • Python installed and available through your system PATH

Commands

Command Description
Run Python Main Runs the currently selected Python entry point
Select Python Main Opens a list of detected Python entry points

How It Works

Python Main Runner:

  1. Searches the workspace for .py files.
  2. Reads each Python file.
  3. Detects the following pattern:
if __name__ == "__main__":
  1. Adds matching files to the available entry point list.
  2. Runs the selected file in a VS Code terminal.

Development

Clone the repository:

git clone <repository-url>
cd python-main-runner

Install dependencies:

npm install

Compile the extension:

npm run compile

Start development mode:

npm run watch

Then press:

F5

inside VS Code to launch the Extension Development Host.


Packaging

Install the VS Code Extension Manager:

npm install -g @vscode/vsce

Create a .vsix package:

vsce package

Install locally:

code --install-extension python-main-runner-x.x.x.vsix

Project Structure

python-main-runner/
│
├── src/
│   └── extension.ts
│
├── package.json
├── tsconfig.json
├── README.md
└── node_modules/

Future Improvements

Possible improvements:

  • Use the VS Code selected Python interpreter instead of system python
  • Support debugging selected entry points
  • Allow command-line arguments
  • Add run profiles
  • Improve Python parsing using the Python AST
  • Add workspace-specific configurations

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft