我可以在同一台Windows计算机上安装Python 3.x和2.x吗?

编程入门 行业动态 更新时间:2024-10-25 14:31:48
本文介绍了我可以在同一台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吗?

本文发布于:2023-11-16 10:41:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603550.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:机上   在同一   Windows   Python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!