It seems like you have some misconfiguration (did you install from python.org or through Windows Store?). As previously stated by @Professor_Joykill the documentation explains;
On Windows, the standard Python installer already associates the .py extension with a file type (Python.File) and gives that file type an open command that runs the interpreter (D:\Program Files\Python\python.exe "%1" %*). This is enough to make scripts executable from the command prompt as ‘foo.py’. If you’d rather be able to execute the script by simple typing ‘foo’ with no extension you need to add .py to the PATHEXT environment variable.
Which means that after you have installed (or tried to restart) you should be able to run a script from the current folder by simply using foo.py
. If you want to run a script by simply typing foo
you need to add the following to PATHEXT:
Press WIN button, then type Edit the system environment variables
and click on Environment Variables
in the dialog box that shows up. From there scroll to PATHEXT
in the lower list named System variables
, click on it and verify that you see something similar to what is show in the image below.

It could be that you also need to reboot or at least restart the command prompt or powershell instance to see the effects. (Also do this if you've reinstalled Python)
If this doesn't work, you need to make sure that py files have actually been association to python through the default application interface in windows:

Microsoft, with it's anti-customer approach has of course made it hard to change these to software installed by means other than through Microsoft Store. So to make changes here, you will either have to go the Registry route, or use a program like Default Programs Editor. Alternatives (and this program) can be seen here.