How to Add a “Run with Python” Option to the Right-Click Menu for .py Files in Windows 11
If you often work with Python scripts on Windows 11, adding a “Run with Python” right-click context menu option can save time. Instead of opening the terminal and typing commands manually, you can run any .py file directly from File Explorer. This can be done by editing the Windows Registry. Below are two simple methods.
Method 1: Manually Edit the Windows Registry
-
Open Registry Editor
Press Win + R, typeregedit, and press Enter. Approve the UAC prompt if it appears. -
Go to the Python file association key
Navigate to:HKEY_CLASSES_ROOT\Python.File\shell
If this path doesn’t exist, ensure Python is installed and
.pyfiles are associated with Python. -
Create a new context menu entry
Right-click shell → New > Key → name itRunWithPython.
In the right pane, double-click (Default) and set its value to Run with Python (or your preferred label). -
Add the execute command
Right-clickRunWithPython→ New > Key → name itcommand.
Double-click (Default) and set:"C:\Program Files\Python311\python.exe" "%1"
Adjust the path to match your Python installation (e.g.,
C:\Program Files\Python312\python.exe). -
Test
Right-click any.pyfile—Run with Python should appear.
Method 2: Use a .reg File (Quick)
-
Create a text file and paste the following (edit the Python path as needed):
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Python.File\shell\RunWithPython] @="Run with Python" [HKEY_CLASSES_ROOT\Python.File\shell\RunWithPython\command] @="\"C:\\Program Files\\Python311\\python.exe\" \"%1\""
-
Save as
Add_Python_Context_Menu.reg(make sure the extension is.reg), then double-click it and choose Yes to import.
Important Notes
- Find your Python path:
Or locate
where python
python.exein File Explorer (often underC:\Program Files\PythonXXor your user directory). - Permissions: If you see access errors, run Registry Editor as Administrator.
- Backup first: Export the Registry (File → Export) or create a System Restore point before changes.
- Keep the console open (optional): If the window closes too fast, append
& pause:"C:\\Program Files\\Python311\\python.exe" "%1" & pause
Final Result
After completing these steps, right-click any .py file and choose Run with Python. Your script runs in a command window—no manual terminal open required.

Join the conversation