How can I open Python files in IDLE from Windows?

13

5

I'm new to Python. I use Python 2.7 and I am running Windows Vista (64-bit). How do I make it when I click on .py scripts... that it opens up in IDLE so I can edit it a snap? Ya know... without having to open IDLE by itself.

I got all the way to C:\Python27\Lib\idlelib but I don't see the IDLE application.

Then when I do right-click and "Default open with" and select the idle.bat file.. I get this:

alt text

test

Posted 2011-01-17T00:18:57.577

Reputation: 400

Anyone ... there? – test – 2011-01-17T03:36:19.857

Answers

15

At least for Python 3.1 (it shouldn't be any different for 2.7), IDLE is located in C:\Python31\Lib\idlelib\idle.bat.

So to make it open Python scripts, right-click a script, go to Open withChoose default program, click Browse, browse to C:\Python27\Lib\idlelib, and select idle.bat (the extension might not show depending on your Windows settings). Remember to check the Always use selected program to open this kind of file button if it isn't checked already.

Peter C

Posted 2011-01-17T00:18:57.577

Reputation: 266

I can't... I get this error :( – test – 2011-01-17T00:44:01.737

http://i.imgur.com/QTsEQ.jpg – test – 2011-01-17T00:48:22.873

Choose "Select a program from a list of installed programs", and then click Browse and follow the rest of my instructions. – None – 2011-01-17T01:55:33.467

I did... THAT's the error I get when I follow those intructions. – test – 2011-01-17T02:21:39.320

Do you ever get to a screen like this? ---> http://img600.imageshack.us/img600/8144/browsescreen.png

– None – 2011-01-17T03:39:45.367

No, I did not. I go to pythonw.exe, click OK, and I do NOT receive that python thingy. :( GRRR VISTA!! – test – 2011-01-17T18:28:14.003

2

Windows 7 Pro 64bit after installing python-3.5.1-amd64.exe had the same issue no edit context after install.

To correct: Right click .py file, open with Choose default program ... then assigned to: c:\users\myusername\AppData\Local\Programs\Python\Python35\pythonw.exe and selected "Always use the selected program to open this kind of file" & the .py files changed to the Python IDE icon & the edit context menu started showing up.

C_J

Posted 2011-01-17T00:18:57.577

Reputation: 21

That path helped me find it, but the program to open with is idle.bat in the idlelib folder. – ThisClark – 2019-10-26T21:59:27.327

0

Peter C is right, for python 3.7 in windows use following steps 1. Navigate to c:\users\myusername\AppData\Local\Programs\Python\Python37\Lib\idlelib\ 2. select the idle.bat and remember to choose 'alway use this app to open' option.

Rajesh Selvaraj

Posted 2011-01-17T00:18:57.577

Reputation: 1

0

Don't you have "Edit with IDLE" among your options when you right-click a .py file? that should be IDLE's default behavior, maybe it can change according to some installation/system settings. I wouldn't set IDLE as the default program to open .py files, that's python's task. Also that would imply you don't get them executed when you double click them or type their extension-complete name in the command line.

If what i said above doesn't work for you, you could add the IDLE path you mentioned to the Path system variable in Windows, so you can type in the command line:

idle file_you_want_to_open.py
or
idle.py file_you_want_to_open.py

Once you add the IDLE path to the Path system variable you can also lauch IDLE typing "idle" in the box you get from windowsbutton-R. As a plus, you could add the .py estension to the PATHEXT system variable to have python scripts execute "by name only" like executables, system commands, compiled programs or whatever you call it.

note: this started as a comment, then got somehow ...lengthy. I believe you can find all i said, just better, in many python tutorials around the internet.

EDIT to fit your edited question: my previuos answer should solve your problem even if your system is not properly set to run .pyw files, anyway just choose "select a program from a list...", if python is not there look for it in its folder. It seems a matter of having python "linked" with .pyw files, like it's supposed to be. Just let me repeat: you don't want to have .py files open in IDLE by default, look at my answer above.

Mattia Gobbi

Posted 2011-01-17T00:18:57.577

Reputation: 101

0

If the file is a module ,i.e. has Python functions which require arguments, then using F5 in the IDLE editor window won't work. Perhaps need to create another file which calls the function with arguments and use F5 to execute that. Use import from filename import * to import the module with the function into this second script and then call the function with its arguments.

David

Posted 2011-01-17T00:18:57.577

Reputation: 11

0

The Python installer usually creates an "Edit with IDLE" context menu entry for .py files.

If it's not there on your machine, you can add it with the following registry file.

  • Save it as edit_with_idle.reg
  • Edit it and replace C:\\Python27 with the correct path to Python on your machine.
  • Import it into your registry by double-clicking it and confirming the warning message.

Reg file:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE]

[HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE\command]
@="\"C:\\Python27\\pythonw.exe\" \"C:\\Python27\\Lib\\idlelib\\idle.pyw\" -e \"%1\""

An "Edit with IDLE" option should now appear when you right-click .py files.

If it doesn't, make sure that .py files are registered correctly: HKEY_CLASSES_ROOT\.py\(Default) should contain Python.File.

Tomalak

Posted 2011-01-17T00:18:57.577

Reputation: 1 109