Python IDLE won't open with .py file, only from start menu - python

I've looked through many similar questions, but no one seems to have had this same problem. I can open the IDLE shell perfectly fine from the start menu. Once in, I can use File->Open to open any .py file.
However, my problem is that if I try to open any .py file from File Explorer with IDLE, the files will run, but the IDLE application won't come up. This especially makes it difficult to quit running when I can't even close the application if it's not open. It also makes it very tedious if I have to always use File->Open from the IDLE shell if I want to open a .py file. How can I at least get the Edit with IDLE option to come back?

I had this same issue and came looking for an answer, but ended up figuring it out:
I had the issue when I downloaded the 64-bit version for windows (3.9.7), but the issue was resolved when I instead installed the 32-bit version of 3.9.7.
Now I can right-click > "Edit with IDLE"

When you open the file from within IDLE, you open it in an edit window. If you try to open it from the file explorer, it will RUN it on IDLE. So that's why you can't just "open it" from the explorer.
I suggest that you start using some other tools to code in python. Sublime Text and Atom are great text editors, and both can be used as a python IDE.

The issue could be outside of Idle as I had the same behavior on OS 12.6. Restarting the Finder from the Force Quit menu resolved.

Related

How do I run .py files by double clicking if I have Anaconda?

I've made a .py file through spyder in my Anaconda navigator, and it works fine when I run it in console (spyder and cmd). The script reads from a website, and appends to a text file. Through spyder and cmd, I always see the addition it's made. But when I double click, it brings up the command window, but makes no addition to the text file. What gives? I've made other .py files through spyder that work perfectly when double-clicked, bringing up the command prompt and running in there. What's the solution? Thanks!
Edit: when I try to add pythonw or python in the Anaconda file through my directory as the default application, Windows just doesn't accept it. The gist of my code, written in python is:
With dataman being a string I define earlier in the code
with open("gymful.txt", "a") as text:
text.write(dataman)
You may need something like PyInstaller. It will package you script into an executable where you can run it by double clicking.
https://www.pyinstaller.org/

How do I get a python program to run instead of opening in Notepad?

I am having some trouble with opening a .py file. I have a program that calls this .py file (i.e. pathname/example.py file.txt), but instead of running the python program, it opens it in Notepad. How to I get it to run?
The program itself takes in a file, and creates an output that is more readable.
Edit: The operating system is Windows 7. And the file that is calling the python is a .bat file.
Edit 2: It looks like I had to reinstall python for some reason... but it looks like it is finally working. Why reinstalling never comes to mind in the first place... And then I had to change how the file extention was opened. Thanks guys
This happened because most probably you have set notepad as the default program to open a .py file. Go to default programs app in windows. Select choose app by extension. Here search for .py files. Change the option from notepad to python. This should solve your problem.
okay.
1) i tried turning it off and on again.
2) i uninstalled and reinstalled python
still no joy. and then!
in windows explorer there's an open with option that sets the default program that windows is pointed toward if you click on the filename or enter it on the command line. change that from notepad or whatever it is if it's not python. change it to python. then presto. no problem-o.
You need to run it from the command line.
http://docs.python.org/2/faq/windows.html#how-do-i-run-a-python-program-under-windows
Are you trying to run the program like this?
/dirdir/MyPythonScript.py
try the following instead
python /dirdir/MyPythonScript.py

.py files not opening in IDLE from OSX Finder?

I recently re-installed Python 2.7.3 from python.org on OSX 10.8.2, and now nothing (literally nothing I can see) happens when I double-click on .py files in Finder, or when I right-click/Open-With/IDLE(2.7.3). (Edit: IDLE is already set as the default program to open .py files; the "right-click" part was just to illustrate I couldn't open them either way.)
I have Tcl/Tk 8.5.13 installed (re-installed after I re-installed Python), and I can open IDLE itself just fine, so this isn't that issue where IDLE won't work without the right version of Tcl/Tk. I can also open .py files from the Terminal using idle -e file.py without a problem.
I did notice that the Python Launcher activates when I open files this way, and is absent when I double-click on .py files in Finder (although again, literally nothing happens when I do this--I have the IDLE icon in my dock and it doesn't start bouncing or anything). Could this be a Python Launcher problem? If not, does anyone know what's going on here?
Update: I tried opening IDLE first and then double-clicking on .py files, and that works. So it seems it's just an issue of IDLE not being opened when you try to open a .py file in the Finder.
I know that means I now have at least three other ways of opening my .py files in IDLE, but I really like just being able to navigate to a file in Finder and open it when IDLE itself is not yet open. So I'd still really like to solve this problem if possible (also I really hate when stuff that's just supposed to work doesn't).
Update: Per Ned Deily's suggestion I checked for errors using Console.app and found:
3/8/13 10:42:38.006 AM com.apple.launchd.peruser.501[276]: ([0x0-0x199199].org.python.IDLE[1975]) Exited with code: 1
pops up whenever I try to double-click a .py file in Finder.
Make sure you have set the intended instance of IDLE as the default application for all .py files. One way to do so is to select a .py file in a Finder window, then select the Finder -> File -> Get Info menu item (or Cmd-I). In the Open with: section, pull down the application menu item and select the desired IDLE; if you have multiple copies of IDLE installed, select the Other.. menu item at the bottom of the list and use the file chooser to select the right version of IDLE. Then, click the Change all... button to Use this application to open all documents like this one. You should now be able to launch a .py file in the desired IDLE by double-clicking. If this doesn't work, examine system.log to see if there are any error messages being logged. You can use the Console utility to examine logs (/Applications/Utilities/Console.app).

Python IDLE hangs when opening/saving files

I just downloaded the latest Python IDLE 3.2 for Windows 7 (64-bit).
I can open, edit, and save existing .py files, but if I open a new document and try to save it, IDLE hangs.
After a few attempts, I tried using a regular text editor to create a hello world program (plain ASCII). But I cannot even open that file: IDLE hangs when trying.
I've searched the web and surprisingly found no hits for this problem. Does anyone have a workaround?
It appears IDLE doesn't cope with paths that have spaces in them. I worked around the problem by choosing directory paths that don't have spaces.

Edit python31 file and it opens notepad and starts python26

I am in python31,
then I go to file open i left click to open file
and it opens in notepad(simple text editor)python31
The moment it opens the notepad, it starts python26
I thought it has something to open with, and I have changed that to python31
And it still opens python26
EDIT:
The file is created by python26, but it is not executable.
I am guessing here, the question it not very clear.
It sounds like the .py extension in Windows is associated with the Python 2.6 runtime. (This normally get setup this way during installation of Python on Windows). You can change this by updating the associated file extensions and programs in Windows.
By double clicking on the file it is not opening the file for editing but instead running it. If you want to edit the file you have to either right-click and select an approriate edit action or open the file from your editor's 'open file' action. (Or change the .py extension to open in your favourite editor)
I had similar problems, and right clicking and changing edit options didn't solve it. You can try repairing python31 installation with running the msi installer and selecting it as the default python

Categories