AHK script to run a Python script with the default interpreter and keep the window open.
This AutoHotkey script runs a Python script with your default Python interpreter and pauses at the end so you can read output/errors.
- Compile this script to an
.exefile. To do this, use Ahk2Exe or install the full AutoHotkey suite and compile from its launcher. - Right-click a Python script and choose
Open with.... - Select
Look for another app on this PCand choose the compiledPython and Wait.exe. - Double-click the Python script to run it.
- If
run-with-python.iniexists withpython_path, that interpreter is used and overrides all auto-detection. - Otherwise, uses
pywhen available, then falls back topython. - Accepts a
.pyfile path from WindowsOpen with. - Forwards any extra command-line arguments to the Python script.
- Verifies the target script exists before running.
- Keeps the terminal open with
pauseso output can be read.
Create run-with-python.ini beside the compiled executable to force a specific interpreter:
[run-with-python]
python_path=C:\Python311\python.exeIf the file exists and python_path is set, that path is used and PATH-based detection is skipped.
- This launcher is Windows-only (AutoHotkey).
- It opens a console window for each run by design.
- It sets the working directory to the launched script's folder before starting Python.
- It does not currently support drag-and-drop multiple files in a single launch.
This approach is intentionally simple and practical for local scripting, but there are trade-offs:
- Good: no registry edits, no custom shell extension, and very easy to distribute as one
.exe. - Good: explicit
pauseimproves usability for scripts that exit quickly. - Risk: behavior depends on PATH and Python launcher availability (
py/python). - Risk: console-focused UX can feel clunky for GUI-oriented Python scripts.
If you want a more robust long-term setup, consider:
- Associating
.pywithpy.exedirectly in Windows settings. - Using a small PowerShell wrapper if you want richer logging or environment setup.
- Adding optional venv detection (e.g., prefer
.venv\\Scripts\\python.exenear the script).