如何获取“ python”以在WSL bash中运行Python 3?

uri*_*rig 5 python bash windows-10 windows-subsystem-for-linux

当我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>
Run Code Online (Sandbox Code Playgroud)

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

我尝试卸载,python-minimal但被告知未安装(!)

为什么我看到两个针对Python的“竞争”软件包?如何解决冲突并配置WSL bash以运行Python 3 python

Cam*_*ind 15

如果您在 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
Run Code Online (Sandbox Code Playgroud)

或者,您可以使用update-alternatives

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
Run Code Online (Sandbox Code Playgroud)


Srd*_*bor 6

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

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

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

  • 不是一个答案,也不是一个好建议或坏建议,这只是开发人员的偏好,这根本不应该是一个答案。 (8认同)
  • 不。[`python2` 已经死了](https://pythonclock.org)。`python` 应该运行 Python 3.x。 (4认同)