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

  1. Open Registry Editor
    Press Win + R, type regedit, and press Enter. Approve the UAC prompt if it appears.

  2. 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 .py files are associated with Python.

  3. Create a new context menu entry
    Right-click shellNew > Key → name it RunWithPython.
    In the right pane, double-click (Default) and set its value to Run with Python (or your preferred label).

  4. Add the execute command
    Right-click RunWithPythonNew > Key → name it command.
    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).

  5. Test
    Right-click any .py file—Run with Python should appear.

Method 2: Use a .reg File (Quick)

  1. 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\""
  2. 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:
    where python
    Or locate python.exe in File Explorer (often under C:\Program Files\PythonXX or 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.

Windows 11, right-click menu, context menu, Python, run Python script, .py files, Registry, .reg file, File Explorer