Run a .py file by double-clicking on it in Windows 10

Question:

I want to double-click on a .py file and have Python execute it in Windows 10. But can’t.

  1. The .py files are showing a black rectangle in Windows Explorer, suggesting that they are not associated with any filetype.
  2. Double-clicking on a .py file gives me an option to open with Notepad, Wordpad, or Look for an App on the Microsoft Store
  3. Python is in my path. On DOS prompt, if I run:
    $ python --version
    ==> Python 3.9.0
    $ where python
    C:UsersBabarAppDataLocalProgramsPythonPython39python.exe
  1. If I try to associate .py with Python using Windows’s ‘Set Default App by Extension’, Python is not offered as an option, only Notepad, Wordpad, or Microsoft Store.
  2. If I try and associate .py to Python, Python is not displayed as an installed app.
  3. If I run the DOS command
$ assoc
.py=C:UsersBabarAppDataLocalProgramsPythonPython39python.exe

But if from the same DOS command, I run:

$ .Hello.py

It again pops the window prompting me to choose Notepad/Wordpad/MS Store app.

Beyond this, I’m out of ideas.
Any suggestions appreciated

Asked By: Babar-Baig

||

Answers:

to debug look in your registry key ComputerHKEY_CLASSES_ROOT.py

OP was able to solve his problem by deleting his registry key

Answered By: flaxon

I’m aware that I’m a little late, bu this might help someone:

When you’re trying to run a GUI python script that wasn’t developed on your PC make sure you first run it from the console and see if Python complains about something.

Many times even experienced users forget that some required modules are not installed on their PC. Until that’s fixed, there is no way he can run the script by double click or shortcut – and there are no warnings/error messages.

Answered By: user3626099
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.