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

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

问题描述

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

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

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.exe pyw.exe 启动器安装到%SYSTEMROOT% C:\Windows )然后与 py 分别是> pyw 脚本。

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:\Python33\python.exe

  • #!python3

  • #!/ usr / bin / env python3

  • #!C:\Python33\python.exe
  • #!python3
  • #!/usr/bin/env python3

以及肆意滥用行为


  • #! notepad.exe

  • #! notepad.exe

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

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