【问题标题】:Running specific python interpreters form command line从命令行运行特定的 python 解释器
【发布时间】:2017-06-17 12:06:14
【问题描述】:

当我打开 CMD(在 Windows 10 上)并输入 python 时,它会初始化 python 3.6.0

C:\>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

现在我最近也安装了 2.7.6 的解释器。如何从 CMD 调用这两个版本的 Python?

期望的结果

C:\>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> ^Z
C:\>python2.6
Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

【问题讨论】:

  • 您可以将python.exe复制或符号链接到python2.7.exe,然后将Python 2.7的安装目录添加到PATH环境变量中。或者只使用 py.exe 启动器,例如py -2 或 py -2.7.

标签: python windows cmd path


【解决方案1】:

你可以使用Python launcher for Windows:

  • Python 2.7 解释器:

    C:\> py -2.7

  • Python 3.6 解释器:

    C:\> py -3.6

您还可以使用特定的解释器运行脚本:

C:\> py -2.7 myScript.py

【讨论】:

    【解决方案2】:

    如果是windows机器,要打开特定版本的python,你可以从命令行使用py。

    示例: py2.7 #for 2.7 版

    和

    py3.6 #for 3.6 版

    如果是 Linux 机器,可以在命令行 python 中使用以下命令

    python2.7 #打开2.7版

    和

    python3.6 #打开3.6版

    【讨论】:

    • 它是py -2.7 和py -3.6。 py 本身用于默认安装最新版本的 Python 2。从 3.6 开始,它使用最新版本的 Python 3。活动的虚拟环境会覆盖此默认值。您也可以通过PY_PYTHON 环境变量覆盖它。
    猜你喜欢
    • 2011-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多