在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?
问题描述
全新的Python,在我开始弄乱事物之前,先进行设置和安装.我的理解是,尽管2.7和Python 3.3的使用都很好,但python 2.7和python 3.3之间还是存在一些明显的差异/不兼容性,所以我认为最好同时安装 both (在它们自己的安装目录中). >
在安装时,我使用了新的3.3功能,其中安装程序为我设置了PATH变量,但是2.7中不存在此选项.安装两个版本后,我尝试了快速测试,打开了命令提示符,然后键入python
进行了交互式会话,并且正如我希望的那样,它启动了python 3.3.
我也知道较短的py
命令.但是,当我在命令提示符下尝试py
时,它会弹出python 2.7.我可以使用py -3
调出3.3,但这会使它比需要的时间更长,并且因为我将主要处理版本3.3,所以我希望py
和
我对Window的PATH系统有些熟悉,但是我不明白为什么会这样.我如何进行设置,以使两者 py
和python
都在Windows命令提示符下键入时会启动Python 3.3交互式会话,除非另有说明,例如通过诸如py -2
之类的东西?
谢谢.
py
是环境变量; PY_PYTHON=3
将使py
改为运行最新的Python 3解释器.
在应用程序目录中创建文件py.ini
,内容如下:
[defaults]
python=3
这与PY_PYTHON
环境变量具有相同的作用.通常,根据Windows版本,您可以在C:\Documents and Settings\[username]\Application Data
或C:\Users\[username]\AppData\Local\py.ini
中找到您的应用程序目录.
您还可以在脚本中添加#!
shebang行(第一行),以通知启动器在双击此类文件时使用Python 3:
#! python3
当您安装了多个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:
Set an environment variable;
PY_PYTHON=3
will makepy
run the latest Python 3 interpreter instead.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 inC:\Documents and Settings\[username]\Application Data
orC:\Users\[username]\AppData\Local\py.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屋!