Python IDLE hangs when opening/saving files - python

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.

Related

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

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.

Strange IDE behaviour with a python file

I'm running Vista SP2 : Python 3.3.5
I have a fairly large .py file (~11k lines) which I'm working on. I recently installed pyscripter and have been using it without issue for a week or so. But yesterday I went into pyscripter and as soon as I added a single new character to the file I got an "Out Of Memory" error. Sure enough it had maxed out all 2GB of ram on my laptop. I tried opening the file in IDLE, and although I could edit the file it would freeze up whenever I tried to run it. However in PythonWin the file opens and runs just fine. I commented out the function that I had last changed wondering if my code was causing the issue, but pyscripter and IDLE are still acting the same.
Anyone experience this before? Any ideas?
I think its to do with the way the GUI opens and displays the file, as i believe IDLE loads the whole thing into RAM when you open it, so the only way to get around that without changing your file would be to add more RAM, a more sensible approach would be to break up your file into smaller chunks, then add import statements at the top of the main file.
This also means that your file can be made easier to work with (assuming you break it up into sensible chunks where the functions are related in each file)
if you are worried about what will happen if you try to compile/package it up for use on other computers, i do this all the time with cx_freeze with no problems.
James

Create a desktop icon for a Tkinter script

I have written a python script with a Tkinter GUI. I would like to create a desktop icon that will execute this script so that the end-user (not myself) will be able to double-click the icon and have the GUI load, rather than 'run' the script from the terminal or python shell and then have to F5 from there.
Is there a way to do this? I have googled many arrangements of my question but most answers seem to be normal python scripts, not ones which are Tkinter based.
I am using a Raspberry Pi with Wheezy and Python 2.7
Thanks in advance.
I create executables(icons that I click to start the programs I write) using 'py2exe'. I use windows 7 and I am not sure if it would work for you with Raspberry Pi, but a google search may clear that up for you. I will provide the link below. Basically you end up with a folder with the executable(icon) and also some files, without which the executable won't work. It's unfortunate that you get this extra 'baggage', but it's still handy and the best solution I have come across. I don't think there is a much better way, but I am not 100% on that. Interestingly, I found that you could delete most of these baggage files and the executable would still work, it was trial and error, but it didn't take long. If I want to send the folder to someone, I zip it first.
py2exe is here
If you need a 64 bit binary you can get it here, along with, actually, pretty much every other version. get py2exe here also
Besides creating executable file other option is create simple .bat file:
Open notepad
Enter "C:\ProgramData\Anaconda3\python.exe" "C:\Users\Your ID\script.py"
First part is path to python.exe, second to your python script
save file as .bat file, ex. "open_program.bat"
Now simply double click on saved .bat file icon should open your script.
I like using cx-freeze to convert python scripts to exe.
There is very easy to follow documentation to do this. In short, you create a setup.py script that specifies what libraries and packages you want to include or exclude in your application.
You can then run the build in the console and it will create a build folder, in which will be an Application File. You can create a Desktop short cut using send to and selecting desktop.
Documentation link
You can save the script as a .pyw file so the user can click on the file and the GUi would open

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

Categories