Set Python IDLE as Default Program to Open .py Extensions [closed]

房东的猫 提交于 2019-11-29 07:06:25
Jarad

If the "always use the selected program to open this kind of file" checkbox is grayed out, ungray it by:

  1. Open regedit Go to
  2. HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts
  3. Find the .py extension among the list
  4. Delete the UserChoice key (folder)

Then you can navigate to: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Python XX and choose IDLE...

or

navigate to C:\...\PythonXX\Lib\idlelib\idle.bat and select that.


---- If You are updating from a previous version of Python ----

I just updated from Python 3.4 to Python 3.5 and it was a nightmare setting IDLE as my default program. I wasted so much time. I finally got it to where I no-longer have to right-click and select IDLE. Instead, I just click on a .py file and it opens IDLE by default... and it has a legit-looking Python icon (not an ugly .bat icon).

I'm posting this so mainly I'll remember how I did this!

  1. Uninstalled Python 3.4 using control panel (Windows).
  2. Deleted remaining C:\Python34 folder entirely.
  3. Went into registry:

    1. Windows "start" orb (bottom-left) > type "run" > type "regedit" in Run dialog box.
    2. Looked in the following areas and deleted python keys entirely:
      • HKEY_CURRENT_USER\Software
      • HKEY_LOCAL_MACHINE\SOFTWARE
      • HKEY_USERS.DEFAULT\Software
      • HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node
    3. (Optional, do with caution) In left pane of Registry Editor, right-click and select "Find". I looked in keys, values and data but looking in just keys might be enough. I deleted the ones that looked very specific to start-up procedures. You can press F3 to find again each time.

  4. I ran CCleaner specifically to remove / clean-up the registry, but also to clean up temp folders and just general maintenance. Run it several times.

  5. Restart computer
  6. Install new version of Python. If installation fails first time, consider un-checking some of the "Advanced Options" during installation. Ex: "download debug binaries".

  7. After you install, .py files may not be associated to a program. You can go to your control panel and set file associations.

  8. Look for .py file extension and click "Change program" button in the top-right. Browse to the location of idle.bat. Example: C:\Python35\Lib\idlelib. Click the idle.bat file and press OK.

At this point, you should be able to click a python file (file with .py extension) and it will open using IDLE's idle.bat program. I've read that sometimes this doesn't work for some people.

But now, the icon of .py files look like the icon of the .bat program. This looks like crap so I did the next steps to associate a Python icon with .py files.

  1. Start > run > regedit (to launch Registry Editor)
  2. In Registry Editor, navigate to: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py\UserChoice and make note of the Progid (Applications\idle.bat in my example).

  3. If UserChoice is not there, navigate to HKEY_CLASSES_ROOT\.py and make note of the (Default) value (ex: py_auto_file).

  4. I didn't know which to change so I changed BOTH.

    1. Go to: HKEY_CLASSES_ROOT\Applications\idle.bat. A "DefaultIcon" folder didn't exist so I right-clicked idle.bat and chose New > Key and named it "DefaultIcon". For the (Default) data, I put C:\Python35\Lib\idlelib\Icons\idle.ico to reference the .ico image that's within the IDLE icons folder.

    2. Go to: HKEY_CLASSES_ROOT\py_auto_file and did the exact same steps as step 12.1.

  5. Restart your computer.

End-result

After all these steps, I am now able to double-click a .py file in Windows and it launches the file in Python IDLE.

  1. Right click on any .py file
  2. Click Open With...
  3. Click Choose a default program...

    IfIDLEis on the list, click it.

    else

    Click Browse, and find the IDLE program

  4. Click OK and voila!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!