Python 自 3.3 版本开始 提供了一个新的 Launcher 来解决 Windows 上面的版本切换问题.
官方描述:
The Python launcher for Windows is a utility which aids in the location and execution of different Python versions. It allows scripts (or the command-line) to indicate a preference for a specific Python version, and will locate and execute that version. reference: 3. Using Python on Windows
这个启动器 py.exe, 默认安装到系统盘的 system32 文件夹里. 如果你同时安装了 Python 2 和 Python 3, 用的时候直接在终端里输入:
py -3
就是打开 Python 3 的 REPL(交互式编程环境), 或者
py -3 example.py
就可以运行 Python 3 的脚本了.
同理, 输入 py -2.7 或者直接输入:
py example.py
使用 Python 2 来运行脚本.
详细说明参见文档 PEP 397 - Python launcher for Windows http://www.python.org/dev/peps/pep-0397/
参考资料
在同一台电脑下如何进行 Python 2 与 3 的切换? - 知乎 https://www.zhihu.com/question/22846291
来源: http://www.mzh.ren/python-version-switcher.html