Hi,
if I open a file from IDLE (Python 3.12.7) and press F5 it runs, but if I double click on a .PY file in Windows Explorer it doesn’t want to run. What could be the problem?
The default is to run the script not edit it I think on Windows.
Try right-click on the file and choose edit option from the context menu.
Where did you find “edit” in my post?
I want to open the .PY file in IDLE by double clicking on a Python file in Windows Explorer and then to press F5 to run it. But it doesn’t want to run that way. It runs only if I open a .PY file through “File > Open” in IDLE.
IDLE is an editor. You want to open .py files in IDLE, i.e. you want to edit them.
Петар,
As others have explained, IDLE is just some program that comes with the Python distribution and is an editor. Many people prefer other editors.
With care, since you are using Windows, you can change the association between a file suffix like .py
so that when you double click on it, it opens with some other program if you are an IDLE worshipper.
That is not necessarily a good idea as self-contained Python programs are expected to just run. It may even be that you could mess up IDLE knowing what to run.
There are many ways to adjust your workflow and a common one is to open IDLE on no file and then internally opening the files you want to edit or selectively run.
And note, if the right-click method to edit the file does not work for you, you can configure Windows to have IDLE be your default.
Or, if you do serious work with python, consider alternative editors or environments that provide more functionality. There are tons of them and I have used many but because I program in other languages, I mainly use RSTUDIO for python too.
OK, editor or not, I just want to know why F5 in IDLE does not run the program opened with double click on the file in explorer.
It worked before I updated Python from older version to 3.12.7.
F5 works, also, when I open the file within IDLE with “File > Open”.
BTW, I use PyCharm, too, but sometimes I just want to use IDLE. Expecially when I want to explain Python to others.
Let me explain again. Double clicking does not normally open a file in IDLE. By default, double clicking a file in File Explorer runs the file with the executable associated with the .py extension. The Windows Python installer has an option to associate the current python.exe being installed with .py. If one installs more than one python.exe, one has to be careful not to click that button unless one really wants to make the new .exe the associated .exe. Changing file associations is possible … and possible to mess up. Perhaps you or someone previously changed the association. Installing 3.12.7 likely changed it back.
The installer will also add Edit with IDLE
to the context menu for .py files, if not present, and Edit with IDLE 3.xy (nn bit)
its associated submenu. Loading the file into an IDLE editor this way* should be the same as loading from IDLE. I just tried it and F5 runs the file as always.
- I just discovered that Edit with IDLE does not always work. I will open a bug issue.
Few days ago it worked both ways, but now:
- Open the file from IDLE, press F5 it runs the program;
- Double click in Explorer opens the file in IDLE, press F5 and it does not run.