如何在 Windows 中同时使用 Python 2.x 和 3.x?
- 安装 Python 2.x 到默认路径,比如
C:\Python27
。 - 安装 Python 3.x 到默认路径,比如
C:\Program Files (x86)\Python35-32
。 - 查看 Python 3 的 pip 版本,
python -m pip --version
。如果还是 7.x.x 的话,使用python -m pip install --upgrade pip
升级到 8.x.x。因为旧版本有路径中含有空格就无法运行的 bug。 - 把 Python 3 的
python.exe
改名为python3.exe
;Scripts\pip.exe
删掉,只留下pip3.exe
。 - 把 Python 2 和 3 的目录都加入环境变量,大功告成。
效果:
PS: 我才知道原来 Windows 也可以用 shebang 指定执行脚本的解释器。
运行结果: