我可以在同一台 Windows 计算机上安装 Python 3.x 和 2.x 吗? [英] Can I install Python 3.x and 2.x on the same Windows computer?

查看:27
本文介绍了我可以在同一台 Windows 计算机上安装 Python 3.x 和 2.x 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行的是 Windows,当您在命令行上运行程序时,shell/OS 会根据注册表设置自动运行 Python.如果我在同一台机器上安装 2.x 和 3.x 版本的 Python,这会中断吗?

I'm running Windows and the shell/OS automatically runs Python based on the registry settings when you run a program on the command line. Will this break if I install a 2.x and 3.x version of Python on the same machine?

我想玩 Python 3,同时仍然能够在同一台机器上运行 2.x 脚本.

I want to play with Python 3 while still being able to run 2.x scripts on the same machine.

推荐答案

官方的共存方案好像是适用于 Windows 的 Python 启动器,PEP 397 包含在 Python 3.3.0 中.安装发布转储 py.exepyw.exe 启动器到 %SYSTEMROOT% (C:Windows)然后分别与 pypyw 脚本相关联.

The official solution for coexistence seems to be the Python Launcher for Windows, PEP 397 which was included in Python 3.3.0. Installing the release dumps py.exe and pyw.exe launchers into %SYSTEMROOT% (C:Windows) which is then associated with py and pyw scripts, respectively.

为了使用新的启动器(无需手动设置您自己的关联),请启用注册扩展"选项.我不太确定为什么,但在我的机器上,它把 Py 2.7 作为(启动器的)默认".

In order to use the new launcher (without manually setting up your own associations to it), leave the "Register Extensions" option enabled. I'm not quite sure why, but on my machine it left Py 2.7 as the "default" (of the launcher).

通过直接从命令行调用脚本来运行脚本将通过启动器路由它们并解析shebang(如果存在).您还可以显式调用启动器并使用开关:py -3 mypy2script.py.

Running scripts by calling them directly from the command line will route them through the launcher and parse the shebang (if it exists). You can also explicitly call the launcher and use switches: py -3 mypy2script.py.

各种shebangs似乎都有效

All manner of shebangs seem to work

  • #!C:Python33python.exe
  • #!python3
  • #!/usr/bin/env python3

以及肆意滥用

  • <代码>#!记事本.exe

这篇关于我可以在同一台 Windows 计算机上安装 Python 3.x 和 2.x 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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