How do I set IDLE as the default editor for Python scripts?

20,781

Solution 1

You didn't mention which idle package you are using, let's assume "Idle". If using "Idle3" then use idle3.desktop below. If using "Idle(using Python-2.7)" then use idle-python2.7.desktop

There are 2 things preventing you from finding idle in the context menus -

First none of the idle .desktops have a MimeType= line in them, that's why Idle doesn't show in the r. click > open with ... menu

Additionally - only .desktops whose Exec= line ends with a %letter will show in the r. click > properties context menu, even if they show up in the above 'open with' menu

So in this case easiest to just do this - first add to the open with menu

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

In the [Added Associations] section look for this line

text/x-python=

If there then add this to the end

idle.desktop;

If not there then just add

text/x-python=idle.desktop;

Idle should now be available in the open with menu, if not log out/in

While there, in the [Default Applications] section look for the same line & replace the .desktop as such, if not there just add the line ( no ; is used in the Defaults section

text/x-python=idle.desktop  

If Idle doesn't show up as the default, even after a restart then you'll need to 'force' it. I'd prefer this way rather than messing with defaults.list

open the .desktop in a root editor

 gksudo gedit /usr/share/applications/idle.desktop

Add a %f to the end of the line, save - like

Exec=/usr/bin/idle -n %f

Then ck. again & see if Idle is now the default, do a log out/in if needed. Once it's added then you can reopen idle.desktop & remove the %f, it should stay as default. I'm not sure if %f is appropriate for idle, otherwise I'd say you could leave it

enter image description here

Solution 2

Here's how you do it:

  1. Go to a folder that contains a Python file.
  2. Right-click on any Python file.
  3. Select Properties.
  4. Next to the section that says “Opens with”, click the Change button.
  5. You may need to select More Options.
  6. Click on Look for another app on this PC.
  7. Navigate to where you installed Python. For me, that’s the Python34 folder on the C drive.
  8. Open Lib
  9. Open idlelib
  10. Select the idle.bat file.
  11. Click Open.
  12. Click OK to close out of Properties.
  13. Now you can open .py files in IDLE simply by double-clicking on them.

We also have a video showing how to associate Python files with IDLE.

Share:
20,781

Related videos on Youtube

Lance Collins
Author by

Lance Collins

Updated on September 18, 2022

Comments

  • Lance Collins
    Lance Collins almost 2 years

    I would like to set IDLE as the default editor for python scripts, but when I click on "open with application" and hit the dropdown to show more applications it isn't an option.

    Here's exactly what I am doing...

    1. right-click on .py file on my desktop.
    2. Right click on properties.
    3. Click on the Open with tab.

    There is no "Use a custom command" option. The same thing happens when I right click on the file and select "open with other application".

    Do you of any way I could set this up?

    • zetah
      zetah over 12 years
      Which Ubuntu version are you using? In 11.04 you can browse to arbitrary program location in "Open with" dialog. For 11.10 I think you can do same with "Properties" dialog
    • Lance Collins
      Lance Collins over 12 years
      I am using 11.04, but IDLE is showing up in the open with other app dialouge.
    • zetah
      zetah over 12 years
      OK then, tick on "Remember this application" and select IDLE from "Open with" dialog
    • Lance Collins
      Lance Collins over 12 years
      Sorry, made a typo. *IDLE is NOT showing up in the open with other app dialouge box.
    • zetah
      zetah over 12 years
      Well, when you select "Other application" a dialog will open. You'll notice at the bottom a roll on/off label "Use a custom command". Just browse then to location of IDLE and tick on "Remember this application" if you want to make it default
    • Lance Collins
      Lance Collins over 12 years
      I saw a screenshot of that online, but I can't replicate it. Here's exactly what I am doing... 1. right-click on .py file on my desktop. 2. Right click on properties. 3. Click on the Open with tab. There is no "Use a custom command" option. The same thing happens when I right click on the file and select "open with other application".
    • zetah
      zetah over 12 years
      Are you sure you are using 11.04? In 11.10 "Custom command" option is on other place
    • Bruno Pereira
      Bruno Pereira over 12 years
    • Bruno Pereira
      Bruno Pereira over 12 years
      Have a look on the link above to create a launcher for your IDE.
    • Lance Collins
      Lance Collins over 12 years
      Turns out I am using 11.10. I'm working at getting the .desktop file to work. Shame they didn't have this functionality by default. It seems like a pretty big oversight.
  • Joël
    Joël over 10 years
    This works in Ubuntu 13.04, without reloading session (but maybe just relaunching Nautilus). Great thanks!
  • Wilf
    Wilf about 10 years
    Make sure you put the entry for IDLE under [Added Associations].