将 Python IDLE 设置为默认程序以打开 .py 扩展 [英] Set Python IDLE as Default Program to Open .py Extensions

查看:192
本文介绍了将 Python IDLE 设置为默认程序以打开 .py 扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Windows 7.我安装了 Python 2.7.8(64 位).今天,我将打开 .py 文件的默认程序从 IDLE 更改为 Windows 命令处理器,并愚蠢地选中了始终使用所选程序打开此类文件"的复选框.

我想要做的是将我的默认程序改回 IDLE.

当我尝试将其改回 IDLE 时,我转到 Control Panel\Programs\Default Programs\Set Associations 并选择 .py 名称并单击更改程序.我确实看到了 python.exe 但选择它没有任何作用.然后我使用浏览"按钮导航到 C:\Python27\Lib\idlelib 但不知道我是否应该选择 idle.py, idle.pywidle.bat 或其他一些会强制默认程序为 IDLE 的 IDLE 程序!

选择其中之一后什么也没有发生.

如何使 IDLE 成为打开 .py 文件的默认程序,并且现在将 Windows 命令处理器与默认程序解除关联?

解决方案

如果

  • 我专门运行 CCleaner 来删除/清理注册表,但也清理临时文件夹和一般维护.运行几次.

  • 重启电脑
  • 安装新版本的 Python.如果第一次安装失败,请考虑在安装过程中取消选中某些高级选项".例如:下载调试二进制文件".
  • 安装后,.py 文件可能不会与程序关联.您可以转到控制面板并设置文件关联.
  • 查找 .py 文件扩展名,然后单击右上角的更改程序"按钮.浏览到 idle.bat 的位置.示例:C:\Python35\Lib\idlelib.单击 idle.bat 文件,然后按 OK.
  • 此时,您应该可以单击一个 python 文件(扩展名为 .py 的文件),它将使用 IDLE 的 idle.bat 程序打开.我读到有时这对某些人不起作用.

    但是现在,.py 文件的图标看起来像 .bat 程序的图标.这看起来很垃圾,所以我做了下一步将 Python 图标与 .py 文件关联起来.

    1. 开始 > 运行 > regedit(启动注册表编辑器)
    2. 在注册表编辑器中,导航到:HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.py\UserChoice 并记下 Progid(应用程序\idle.bat 在我的例子中).
    3. 如果 UserChoice 不存在,请导航到 HKEY_CLASSES_ROOT\.py 并记下 (默认) 值(例如:py_auto_file).
    4. 我不知道要更改哪个,所以我更改了两者.

      1. 转到:HKEY_CLASSES_ROOT\Applications\idle.bat.DefaultIcon"文件夹不存在,所以我右键单击 idle.bat 并选择 New > Key 并将其命名为DefaultIcon".对于(默认)数据,我将 C:\Python35\Lib\idlelib\Icons\idle.ico 放入引用 IDLE 图标文件夹中的 .ico 图像.

      2. 转到:HKEY_CLASSES_ROOT\py_auto_file 并执行与步骤 12.1 完全相同的步骤.

    5. 重新启动计算机.

    最终结果

    完成所有这些步骤后,我现在可以在 Windows 中双击 .py 文件并在 Python IDLE 中启动该文件.

    I am on Windows 7. I have Python 2.7.8 (64 bit) installed. Today, I changed the default program that opens .py files from IDLE to Windows Command Processor and stupidly selected the checkbox that said "always use the selected program to open this kind of file".

    What I want to do is change my default program back to IDLE.

    When I attempt to change it back to IDLE, I go to Control Panel\Programs\Default Programs\Set Associations and select the .py name and click Change Program. I do see python.exe but selecting that does nothing. I then use the "Browse" button to navigate to C:\Python27\Lib\idlelib but don't know if I should select idle.py, idle.pyw, idle.bat or some other IDLE program that will force the default program to be IDLE!

    Nothing happens after I select one of these.

    How do I make IDLE be the default program that opens .py files and now disassociate Windows Command Processor from being the default?

    解决方案

    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.

    这篇关于将 Python IDLE 设置为默认程序以打开 .py 扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆