Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python is not opening .py files [closed]

I'm trying to open a .py script on my computer but it unfortunately keeps opening in Notepad. I've tried changing the associations on my computer but even when I browse to python.exe and click it, it won't show up as a usable program (interestingly, pythonw.exe can be associated with it but nothing opens when I click on the file that's associated to pythonw). Is there any way I can fix this issue? If not, how can I run my script from the Python interpreter by hand?

Also, I've tried reinstalling Python, and that didn't help.

like image 916
gadmaget Avatar asked Dec 22 '25 10:12

gadmaget


2 Answers

You can check the registry to see what is associated with .py and .pyw files. For me .py is associated with Python.File, which uses this for its shell\open command:

"C:\Python27\python.exe" "%1" %*

Similarly, .pyw is associated with Python.NoConFile which opens with pythonw.exe. Look for these extensions and file types as keys under HKEY_CLASSES_ROOT.

You can also use the ASSOC and FTYPE commands from a console window to check these:

C:\projects>assoc .py
.py=Python.File

C:\projects>ftype python.file
python.file="C:\Python27\python.exe" "%1" %*

They also have command line variations to allow you to set new values. Check their help screens for more info, and search Stack Overflow for numerous examples.

like image 107
Todd Avatar answered Dec 24 '25 00:12

Todd


The standard way of executing a python script on Windows is calling the python interpreter with the script name as parameter on the (DOS) command line. It is necessary though that the path to python.exe is included in your Path system variable.

python myprogram.py
like image 44
Markus M. Avatar answered Dec 24 '25 00:12

Markus M.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!