Python Is Not Opening. Py Files [Closed]

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.

4 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.

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

I used IDLE in the past to run scripts I was working on.

From IDLE's Edit menu you should be able to run the open script.

1

If you are on a Windows OS with IDLE installed, right-clicking a .py file should offer you the option to edit in IDLE.

1
Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.