我正在运行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吗?
发布评论