在 CMD “python"中启动 Python 3.3,“py"启动 Python 2.7,我该如何更改? [英] In CMD "python" starts Python 3.3, "py" starts Python 2.7, how do I change this?

查看:27
本文介绍了在 CMD “python"中启动 Python 3.3,“py"启动 Python 2.7,我该如何更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全新的 Python,只是在我开始处理事情之前设置并安装了东西.我的理解是 Python 2.7 和 Python 3.3 之间存在一些显着差异/不兼容性,尽管这两个版本都很好用,所以我认为最好安装两者(在它们自己的安装目录中).>

安装时,我使用了新的 3.3 功能,其中安装程序为我设置了 PATH 变量,但是 2.7 不存在此选项.安装两个版本后,我尝试了一个快速测试,打开命令提示符,然后输入 python 以打开一个交互式会话,正如我所希望的,它打开了 python 3.3.

我也知道更短的 py 命令.但是,当我在命令提示符下尝试 py 时,它会显示 python 2.7.我可以使用 py -3 来启动 3.3,但这使得它比实际需要的时间更长,而且鉴于我将主要处理 3.3 版,我想要 py python 都可以启动 Python 3.3 交互式会话.

我对 Window 的 PATH 系统有些熟悉,但我不明白为什么会这样.我如何设置它以便 pypython 在输入 Windows 命令提示符时将启动 Python 3.3 交互式会话,除非另有规定,例如通过类似 py -2?

谢谢.

解决方案

pyWindows Python 启动器,它可以启动任何 Python 版本.

在大多数系统上,py 被配置为默认启动 Python 2.7(如果存在)(这是默认设置,除了 Python 3.6 和更新版本,Python 3 将改为运行).如果你想改变它,你有两个选择:

  1. 设置环境变量;PY_PYTHON=3 将使 py 运行最新的 Python 3 解释器.

  2. 在您的应用程序目录中创建一个文件 py.ini,内容如下:

    [默认值]蟒蛇=3

    这与 PY_PYTHON 环境变量具有相同的效果.通常,您的应用程序目录位于 C:Documents and Settings[username]Application DataC:Users[username]AppDataLocalpy.ini代码>,取决于 Windows 版本.

您还可以在脚本(第一行)中添加一个 #! shebang 行,以告诉启动器在双击此类文件时使用 Python 3:

#!蟒蛇3

当您安装了多个 Python 3 解释器时,

py 也可以配置为使用特定的 Python 版本.

Brand new Python, just getting things set up and installed before I start messing around with things. My understanding is that there are some notable differences/incompatibilities between Python 2.7 and Python 3.3, though both versions are well used, so I thought it best to install both (In their own install directories).

When installing, I used the new 3.3 feature where the installer set the PATH variables for me, however this option is not present for 2.7. After installing both versions, I tried a quick test, opened command prompt, and typed python to bring up an interactive session, and as I hoped, it brought up python 3.3.

I am also aware of the shorter py command. However when I try py in command prompt, it brings up python 2.7. I can use py -3 to bring up 3.3, but that makes it longer than it needs to be, and seeing as I will be dealing primarily with version 3.3, I would like py and python to both bring up a Python 3.3 interactive session.

I am somewhat familiar with Window's PATH system, but I can't see why this is happening. How can I set it up so that both py and python, when typed into a windows command prompt, will start a Python 3.3 interactive session unless otherwise specified, e.g. via something like py -2?

Thanks.

解决方案

py is the Windows Python launcher, and it can start any Python version.

On most systems py is configured to launch Python 2.7 by default if present (this is the default except for Python 3.6 and newer, where Python 3 will be run instead). You have two options if you want to change that:

  1. Set an environment variable; PY_PYTHON=3 will make py run the latest Python 3 interpreter instead.

  2. Create a file py.ini in your application directory with the contents:

    [defaults]
    python=3
    

    This has the same effect as the PY_PYTHON environment variable. Typically, your application directory is found in C:Documents and Settings[username]Application Data or C:Users[username]AppDataLocalpy.ini, depending on the Windows version.

You can also add a #! shebang line to your scripts (first line) to tell the launcher to use Python 3 when you doubleclick such a file:

#! python3

py can also be configured to use specific Python versions when you have multiple Python 3 interpreters installed.

这篇关于在 CMD “python"中启动 Python 3.3,“py"启动 Python 2.7,我该如何更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆