Reputation: 45
I just uninstalled and reinstalled python on my Windows machine. Before I uninstalled my previous version I was able to just double-click on a python script and it would open the command prompt, run the script, and close automatically. After re-installing with the newest version (3.9), I am no longer able to execute the script like that with a double-click.
Clearly I had done something special last time to set that up for myself, but I don't remember what it was. Any idea how I can get that double-click deal going again?
Upvotes: 3
Views: 5287
Reputation: 2393
Save the following text to a file called something like python.reg
(the .reg extension is important). You might need to modify the last line to be your exact path to python.exe
!
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Python.File\shell\open]
[HKEY_CLASSES_ROOT\Python.File\shell\open\command]
@="\"C:\\Python2.7\\python.exe\" \"%1\" %*"
Find the python.reg
file you just saved and double-click it to load those contents into your Registry. If you've performed one of the other operations in other answers (like "Open With"), those "UserChoice" settings are stored somewhere else in the Registry and will override the "Classes" setting shown in this script. So, do one or the other, don't combine them!
Upvotes: 1
Reputation: 2087
Doing the following should fix it:
Explanation:
Your Python scripts have to be processed by another program called the Python interpreter. The interpreter reads your script, compiles it into bytecodes, and then executes the bytecodes to run your program.
Installing a new version might have messed the path to the Python interpreter. The steps listed above will tell Windows to associate .py files with your Python interpreter, thus fixing the issue.
This link with Python on Windows FAQ might also be of help.
Upvotes: 2
Reputation: 23
There will be an option of "Open With" after right-click on the file go and choose CMD. I hope it helps if not then sorry. Because I use Parrot OS
Upvotes: 0