如何在 WSL bash 中将 `python` 变为 运行 Python 3?

How to get `python` to run Python 3 in WSL bash?

当我在 Windows 10 主页中的 bash shell(Windows Linux 的子系统)中键入 python 时,我得到以下错误消息:

The program 'python' can be found in the following packages:
 * python-minimal
 * python3
Try: sudo apt install <selected package>

我已经尝试安装 python3,但我被告知它已经安装并且是最新的。

我已尝试卸载 python-minimal,但系统提示未安装 (!)

为什么我看到 Python 有两个 "competing" 包裹?如何解决冲突并将我的 WSL bash 配置为 运行 Python 3 from python?

python 在 linux 世界中作为 CLI 命令几乎总是意味着 python2 而不是 python3。确保您已安装 python2 (sudo apt install python)。

不要 别名 pythonpython3 - 这是一些糟糕的建议!

要运行 python3,您必须在CLI 上指定python3

如果您在 WSL 下 运行 Ubuntu 20 岁,则有一个名为 python-is-python3 的新软件包:

cameron@Nook:/mnt/c/Users/camer$ sudo apt install python-is-python3
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  python-is-python3
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 2364 B of archives.
After this operation, 10.2 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 python-is-python3 all 3.8.2-4 [2364 B]
Fetched 2364 B in 0s (7208 B/s)
Selecting previously unselected package python-is-python3.
(Reading database ... 33571 files and directories currently installed.)
Preparing to unpack .../python-is-python3_3.8.2-4_all.deb ...
Unpacking python-is-python3 (3.8.2-4) ...
Setting up python-is-python3 (3.8.2-4) ...
cameron@Nook:/mnt/c/Users/camer$ python --version
Python 3.8.10

或者,您可以使用 update-alternatives:

sudo update-alternatives --install /usr/bin/python python $(readlink -f $(which python3)) 3