萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網路程式設計 >> 程式語言綜合

Windows 修復 Python .py 檔案右鍵缺少「Edit with IDLE」選項

現象

  • 雙擊 .py 無法啟動 IDLE 編輯
  • 右鍵選單缺少「Edit with IDLE」

方法一:重新關聯執行檔

  1. 右鍵 .py → 開啟方式 → 選擇其他應用程式
  2. 勾選「一律使用此應用程式開啟 .py 檔案」
  3. 瀏覽選擇 pythonw.exe(無主控台視窗)或 python.exe

方法二:匯入登錄檔(推薦,一次修復)

建立 fix_idle.reg,內容如下(請將路徑替換為實際安裝路徑):

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Python.File\shell\Edit with IDLE]
@="&Edit with IDLE"

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

雙擊執行 → 是 → 確定 → 重新開機或重新登入即可生效。

方法三:手動編輯登錄

  1. Win+R 輸入 regedit
  2. 瀏覽至 HKEY_CLASSES_ROOT\Python.File\shell
  3. 新增金鑰 Edit with IDLE,預設值 &Edit with IDLE
  4. 其下新增 command,預設值填入上述命令列

驗證

右鍵任意 .py 檔案,應出現「Edit with IDLE」選項,點選後以 IDLE 開啟原始碼。

注意事項

  • 路徑中的反斜線須雙重跳脫(\\\\)
  • 若使用虛擬環境,指向該環境的 pythonw.exe 與 idle.pyw
  • Windows 10/11 可能需管理員權限寫入 HKCR
copyright © 萬盛學電腦網 all rights reserved