cmd打开python3解释器,在CMD中,“ python”表示启动Python 3.3,“ py”启动Python 2.7,我该如何更改?...

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 make py 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 in C:\Documents and Settings\[username]\Application Data or C:\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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值