How can I make IDLE the default editor for Python files?

You can easily associate the .py files with IDLE. You have to right click a python script, choose "Open with -> Other application", then choose IDLE from the list with the checkbox asking if it should be the default application ticked. I use XFCE, but Gnome's Nautilus should be similar.

enter image description here

Alternatively, there is a configuration file in your home directory which contains the list of default applications. You can access it on the following path:

~/.local/share/applications/mimeapps.list

You can extend it with the following line:

text/x-python=idle.desktop

where idle.desktop stands for the desktop file of the IDLE version you would like to use, for instance idle-python2.7.desktop or idle-python3.desktop based on the python version you have to use.

NOTE:

Be aware of the permissions of your scripts. If it has the executable permission, despite the default application, your system won't open it in IDLE, as it will try to execute it.


The problem you have is caused by the default installed idle → desktop association.

Nautilus, at least on my 12.04 Ubuntu (Classic Desktop), doesn't seem to have anything with which you can associated (new) commands with a certain filetype (as some Desktops/Browsers) and the list doesn't show idle at all, even if installed via apt-get install idle:

enter image description here

You can get the screen by right clicking a .py file, selecting Properties then the Open With TAB, and then click Show other applications (going via the Open With menu gets you the same result).

You have to correct the .dekstop file for idle by editing /usr/share/applications/idle-python2.7.desktop as root (you might have idle-python3.desktop, depending on what version of idle you installed).

[Desktop Entry]
Name=IDLE (using Python-2.7)
Comment=Integrated Development Environment for Python (using Python-2.7)
Exec=/usr/bin/idle-python2.7 -n %f
Icon=/usr/share/pixmaps/python2.7.xpm
Terminal=false
Type=Application
Categories=Application;Development;
StartupNotify=true

What is missing in the installed file is the %f at the end of the Exec= line. Add %f there and save. Then in nautilus, right click a .py file and navigate to the Properties and Open With TAB once more (you don't have to restart nautilus). Now scroll down and Idle (using Python-2.7) is a selectable option (either as recommended application) or else first click it in the show other application list:

enter image description here

You can use Set as default to always open .py files with idle.

Tags:

Xdg