由于我自己的愚蠢,我以某种方式将 python 命令设置为运行 python 3 而不是默认的 python 2。如何撤消此操作?我在 Ubuntu 18.04 上。
$ python -V
Python 3.7.6
$ python3 -V
Python 3.7.6
最佳答案
您可以列出已安装的所有 Python 版本并更改默认 Python 版本在终端上尝试以下命令。
$:~# update-alternatives --config python
There are 4 choices for the alternative python (providing /usr/local/bin/python).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python3 4 auto mode
1 /usr/bin/python2.7 2 manual mode
* 2 /usr/bin/python3 4 manual mode
3 /usr/bin/python3.7 3 manual mode
4 /usr/bin/python3.8 4 manual mode
Press <enter> to keep the current choice[*], or type selection number: 4
update-alternatives: using /usr/bin/python3.8 to provide /usr/local/bin/python (python) in manual mode
使用 python 版本设置默认的 python 版本。最后,您可以检查命令是否成功,如下所示。
root@kali:~# python --version
Python 3.8.2
它应该显示 Python 2.x
在你的情况下。
关于python - 你如何设置 "python"命令指向 python2 而不是 python3?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62697609/