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

编程入门 行业动态 更新时间:2024-10-25 10:31:23
本文介绍了我可以在同一台 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.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:Python33python.exe
  • #!python3
  • #!/usr/bin/env python3

以及肆意滥用

  • #!记事本.exe

更多推荐

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

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

发布评论

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

>www.elefans.com

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