You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:在CMD中调用Python 3.6却默认启动Python 2.7的问题

Fixing Python 3.6 Not Launching Instead of Python 2.7 in CMD

Hey there, I’ve dealt with this exact headache before—when PATH edits don’t seem to stick, it’s usually something deeper than just environment variables. Let’s walk through the most reliable fixes:

1. Use the Official Python Launcher (py.exe)

Windows comes with a built-in Python launcher designed to manage multiple versions. It’s probably already installed with your Python 3.6 setup, so try these commands first:

  • Launch Python 2.7: py -2
  • Launch Python 3.6: py -3
  • To set Python 3.6 as the default when you type py (or even python if configured), create a py.ini file:
    1. Open Notepad and paste this:
      [defaults]
      python=3.6
      
    2. Save it as py.ini (make sure it’s not saved as py.ini.txt) in either:
      • C:\Windows (system-wide default)
      • %USERPROFILE%\AppData\Local\Programs\Python\Launcher (user-specific default)

2. Fix Windows Registry Entries

Sometimes Windows caches the Python path in the registry, overriding your PATH settings. Here’s how to update it:

  1. Open the Registry Editor by pressing Win+R, typing regedit, and hitting Enter.
  2. Navigate to HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command
  3. Double-click the Default value and replace the path with your Python 3.6 executable (e.g., C:\Python36\python.exe "%1" %*).
  4. Next, go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\python.exe
  5. Update the Default value to your Python 3.6 path as well.

Note: Always back up the registry before making changes—right-click the key and select "Export" to save a backup file.

3. Disable Windows App Execution Aliases

Windows has a feature that can hijack python commands even if your PATH is correct. Let’s turn those off:

  1. Open Windows Settings (Win+I) → Apps → App execution aliases.
  2. Look for entries like "Python.exe" or "Python3.exe" and toggle them Off. This prevents Windows from overriding your actual Python installations.

4. Restart Your CMD Session

Old CMD windows cache the environment variables from when they were opened. Even if you updated PATH, you need to close all existing CMD windows and open a new one for changes to take effect.

5. Quick Fix: Rename Executables

If you need an immediate workaround, you can rename the Python executables to avoid confusion:

  • Go to your Python 3.6 install folder (e.g., C:\Python36), rename python.exe to python3.exe.
  • Now you can launch Python 3.6 with python3 and Python 2.7 with python in CMD.

Most of the time, using the py launcher is the cleanest long-term solution—it’s made for exactly this scenario of managing multiple Python versions on Windows.

内容的提问来源于stack exchange,提问作者Tissuebox

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:10:08