gpt4 book ai didi

在从命令行运行的 Windows 上安装 Python 3

转载 作者:太空狗 更新时间:2023-10-29 18:15:59 25 4
gpt4 key购买 nike

只是好奇,为什么没有在 Windows 上安装 Python 3.x 以使用命令行“python3”默认运行,就像在 Mac OSX 和 Linux 上一样,有什么特别的原因吗?有没有某种方法可以配置 Python 使其像这样运行?谢谢。

编辑:补充一下,我问的原因是因为我的计算机上同时安装了 Python 2 和 3 解释器,所以它是模棱两可的,因为两者都是使用命令“python”运行的。

最佳答案

the reason I am asking is because I have both the Python 2 and 3 interpreter installed on my computer, and so it is ambiguous, as both are run using the command "python".

运行 Python 2 可执行文件:

C:\> py -2

运行 Python 3 可执行文件:

C:\> py -3

其中 pyPython launcher与您的 Python 3 安装捆绑在一起。

py 识别 shebang(例如,#!/usr/bin/env python3 导致运行 Python 3 可执行文件),它尊重 virtualenv(如果你运行 py 而不指定显式 python 可执行版本)即运行:

C:\> py your_script.py

并且会自动使用正确的 Python 版本——您无需在命令行中明确指定 Python 版本。

is there a particular reason why Python 3.x is not installed on Windows to run default with the command line "python3", like it does on Mac OSX and Linux?

OSX 和 Linux 通常默认安装 python 可执行文件,目前大多数情况下它指的是 Python 2 版本,这就是为什么您需要单独的 python3在那里命名。

默认情况下,Windows 上没有 Python。因此,您安装的任何版本都只是 python(我猜)。管理多个 Python 版本的推荐方法是使用 Python 启动器。

Is there some kind of way to configure Python so that it runs like this?

如果你想输入 python3 some_script.py 而不是 py some_script.py 或者甚至只是 some_script (假设 .py 位于 %PATHEXT% 中,Python 启动器配置为运行 Python 脚本(检查 assoc .pyftype Python.File) -- 默认)然后创建一个 bat 文件,例如 python3.cmd 并将其放入 %PATH%:

"C:\path to\Python 3.X\python.exe" %*

关于在从命令行运行的 Windows 上安装 Python 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34212036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com