简体   繁体   English

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

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

When I type python into my bash shell (Windows Subsystem for Linux) in Windows 10 Home, I get the following error message:当我在 Windows 10 Home 的 bash shell(Linux 的 Windows 子系统)中输入python ,我收到以下错误消息:

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

I've tried installing python3 but am told it's already installed and up to date.我试过安装python3但被告知它已经安装并且是最新的。

I've tried uninstalling python-minimal but am told it's not installed (!)我试过卸载python-minimal但被告知它没有安装(!)

Why am I seeing two "competing" packages for Python?为什么我会看到两个“竞争”的 Python 包? How can I fix the conflict and configure my WSL bash to run Python 3 from python ?如何解决冲突并将我的 WSL bash 配置为从python运行 Python 3?

python in linux world as a CLI command almost always means python2 and not python3 . python在 linux 世界中作为 CLI 命令几乎总是意味着python2而不是python3 Make sure that you have python2 installed ( sudo apt install python ).确保你已经安装了python2 ( sudo apt install python )。

DO NOT alias python to python3 - this is some bad advice!不要将python别名为python3 - 这是一些不好的建议!

To run python3 , you have to specify python3 on the CLI.要运行python3 ,您必须在 CLI 上指定python3

If you're running Ubuntu 20 under WSL, there is a new package called python-is-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

Alternatively, you could use update-alternatives :或者,您可以使用update-alternatives

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM