如何让“python”在 WSL bash 中运行 Python 3?

2024-01-24

当我打字时python进入 Windows 10 Home 中的 bash shell(适用于 Linux 的 Windows 子系统)时,我收到以下错误消息:

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

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

我尝试过卸载python-minimal但我被告知它没有安装(!)

为什么我会看到两个“竞争”的 Python 包?如何修复冲突并配置 WSL bash 以运行 Python 3python?


如果您在 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何让“python”在 WSL bash 中运行 Python 3? 的相关文章

随机推荐