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.
- 🔍 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:
.gitnode_modules__pycache__venv.venv
Given this project:
my-project/
│
├── src/
│ ├── main.py
│ └── server.py
│
├── tools/
│ └── migrate.py
│
└── README.md
With:
if __name__ == "__main__":
print("Application started")if __name__ == "__main__":
print("Server started")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.
- Open a Python project folder in VS Code.
- Python Main Runner automatically searches for entry points.
- Use the Python Main Runner toolbar button.
- Select the Python entry point you want to use.
- Press the run button to execute it.
The selected entry point is saved and restored when reopening the project.
- Visual Studio Code
1.125.0or newer - Python installed and available through your system PATH
| Command | Description |
|---|---|
Run Python Main |
Runs the currently selected Python entry point |
Select Python Main |
Opens a list of detected Python entry points |
Python Main Runner:
- Searches the workspace for
.pyfiles. - Reads each Python file.
- Detects the following pattern:
if __name__ == "__main__":- Adds matching files to the available entry point list.
- Runs the selected file in a VS Code terminal.
Clone the repository:
git clone <repository-url>
cd python-main-runnerInstall dependencies:
npm installCompile the extension:
npm run compileStart development mode:
npm run watchThen press:
F5
inside VS Code to launch the Extension Development Host.
Install the VS Code Extension Manager:
npm install -g @vscode/vsceCreate a .vsix package:
vsce packageInstall locally:
code --install-extension python-main-runner-x.x.x.vsixpython-main-runner/
│
├── src/
│ └── extension.ts
│
├── package.json
├── tsconfig.json
├── README.md
└── node_modules/
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